Fatal error: Uncaught exception 'Fuel\Core\FuelException' with message 'The session data stored by the application in the cookie exceeds 4Kb. Select a different session storage driver.' in /home/zeeshankhattak/projects/fuelphp/folio/fuel/core/classes/session/driver.php:464 Stack trace: #0 /home/zeeshankhattak/projects/fuelphp/folio/fuel/core/classes/session/cookie.php(111): Fuel\Core\Session_Driver->_set_cookie(Array) #1 [internal function]: Fuel\Core\Session_Cookie->write('', Array) #2 /home/zeeshankhattak/projects/fuelphp/folio/fuel/core/classes/event/instance.php(163): call_user_func(Array, '', Array) #3 /home/zeeshankhattak/projects/fuelphp/folio/fuel/core/classes/event.php(75): Fuel\Core\Event_Instance->trigger('shutdown', '', 'none', true) #4 /home/zeeshankhattak/projects/fuelphp/folio/fuel/core/bootstrap.php(33): Fuel\Core\Event::shutdown() #5 [internal function]: {closure}() #6 {main} thrown in /home/zeeshankhattak/projects/fuelphp/folio/fuel/core/classes/session/driver.php on line 464
Your code snippet doesn't use the session class, so that is absolutely not the cause of the problem. Passing validation objects to a view is unrelated to the error message.
That must be something in the code, and not related to the session. If you get to the 4K boundary for cookies, you would loose the entire session, including logged-in state, and not only the last product.
Since I don't know the "cart package", I can't really comment on what is going on, I guess some debugging is in order.
You could (temporary) switch to database sessions, those are stored as serialized array's, so you can see what exactly is stored in the session. It might help with the debugging.
Thanks for the prompt reply. I switch to the database session. It works, but a lot of informations are save in DB. I tried the file session and it works too.
I think i will keep this solution.
But I don't understand why the cookie sessions is not appropriate in this case ...
I can't say, I can only imagine that (also given your reply) the cart package saves a lot of data in the session.
Don't forget that cookies are encrypted, and it is the encrypted size that counts, so it's quite possible for a session containing an array of 8 products, encrypted, to produce a string larger than 4Kb.
So anything you want to do, you have to do before you redirect. The only things that will be executed after a redirect are events that are triggered after the contoller has finished.