Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Session flash dissapear after redirect
  • I have problem when I want to get session flash in fuelphp v1.6.1

    //check if validation not valid
    if (!$val->run()) {
             Session::set_flash('errors', $val->error());
             Session::set_flash('input', $val->input());
             Response::redirect('/');
    }

    // get session in top page 
    $errors = Session::get_flash('errors');
    var_dump($errors);

    but I cannot get the result of value session.

    if I am change get session before redirect that is show

    //check if validation not valid
    if (!$val->run()) {
             Session::set_flash('errors', $val->error());
             Session::set_flash('input', $val->input());
             var_dump(Session::get_flash('errors'));exit;
    }

    this is bug ? I don't know ? any suggestion ?
  • Are you using cookies for session storage?

    If you, so probably have hit the size limit of the cookie, validation objects are quite large and should not be stored in the session.
  • I am not using cookie just session only, i think so validation has big data so maybe cannot store in cookie, do you have any suggestion ? , i think my code is simple so i will keep like that, but if you have another solution for solve validation error message, it;s will be nice .
  • in old version  is work v1.4, i don't know why
  • I mean what do you use to store the session data in, what have you configured as driver in your session.php configuration file?

    If that says cookie, your storing all session data in the cookie, and that has a limit of 4Kb. With luck you can get 2 validation objects in that, but probably not.

    Instead of passing the entire object, just pass the messages. Or redesign the application flow, I usually redirect away after success, and let the code fall through on an error. Then you don't need to store anything in the session, you can pass everything directly to the view...

    Look at the registration method example here for example: http://docs.fuelphp.com/packages/auth/examples/auth.html, it shows you the flow I normally use...
  • in my session configuration I am using driver file for store session
    ------------------------------------------------------------------------------------------------------------------------
    <?php
    /**
     * Part of the Fuel framework.
     *
     * @package    Fuel
     * @version    1.0
     * @author     Fuel Development Team
     * @license    MIT License
     * @copyright  2010 - 2012 Fuel Development Team
     */

    /**
     * NOTICE:
     *
     * If you need to make modifications to the default configuration, copy
     * this file to your app/config folder, and make them in there.
     *
     * This will allow you to upgrade fuel without losing your custom config.
     */


    return array(
    /**
    * global configuration
    */

    // set it to false to prevent the static session from auto-initializing, know that it might make your session
    // expire sooner because it's not updated when it's not used. note that auto-initializing always loads the default driver
    'auto_initialize' => true,

    // if no session type is requested, use the default
    'driver' => 'file',

    ------------------------------------------------------------------------------------------------------------------------------------------------------

    if I am passing directly I am worried some code create recursively , example

                    //checking method
                    if (Input::method() == 'GET') {
                        $data['title'] = 'Register Users';
                        $data['photos'] = $photos;
                        return Response::forge(View::forge('frontend/users/_form.twig', $data));                }

                    //check if validation not valid
                    if (!$val->run()) {
                        
    $data['title'] = 'Register Users';
                        $data['photos'] = $photos;
                        $data['errors'] = $val->error();
                        $data['inputs'] = $val->input();
                        return Response::forge(View::forge('frontend/users/_form.twig', $data));

                    }

    It's not simple and clear i think , if using session it's nice because we don't use recursive params for passing to the view.
  • Ok, the file driver should not have a size restriction.

    Have you looked at the example? There is no redundant code in there, it just falls though, and ends with creating the view, no matter what happened before (initial load, reload on error, etc).
  • ok , maybe it's little difficult to explain, but it's possible to keep one old my handling error message using session ?, because now I am still cannot get session flash for that.
  • You can get anything out of the session, or only that?

    Which version of Fuel are you on? What if you use set() instead of set_flash()?
  • hi, if I am using set not set_flash it's work, my fuelphp version is v1.6.1.

    do you know what happen?
  • No, set() and set_flash() are treated equally in the code, and saved at the same time and the same way.

    You don't have a second redirect somewhere, so that it redirects twice before getting to the method that fetches the flash data? Because flash data expires on the next page request.

    Unless you set 'flash_auto_expire' to false in your config, in which case the flash variable remains available until you get_flash() it.
  • yes i know that, but it's happen when I am setup v1.6.1 if in old  version that is work

    I am already config my session // if false, expire flash values only after it's used  (optional, default = true)
    'flash_auto_expire' => false,

    like you said, i just redirect one page, so , actually that page will be get the session.

  • HarroHarro
    Accepted Answer
    Just took one of our existing applications, and added this to the action_create method:

    if ($e = \Session::get_flash('errors', false))
    {
        $i = \Session::get_flash('input', false);
        \Debug::dump($e, $i);
    }

    if ($post = \Input::post())
    {
        if ($form->validation()->error())
        {
             \Session::set_flash('errors', $form->validation()->error());
             \Session::set_flash('input', $form->validation()->input());
             \Response::redirect(\Uri::current());
        }
    }

    Which as far as I can see does what you do, only with a different redirect URL.

    We use a standard session setup (so with auto expire of flash variables), and we use DB as session backend. And we run 1.7/develop, but afaik there are no differences in the session code.

    If I request this URL, and submit the empty form (which causes 6 validation errors), it reloads the page and displays the two dumps without problems. So no issues with flash variables here.

    When I change the session driver to "file", it behaves exactly the same.

    So I'm pretty sure it's not something caused by the framework.
  • hi  your code work for me, thanks for that, I don't know the reason why my old code is cannot get session.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion