Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Setting session variables
  • Session variables can be set with an array and then retrieved using dot syntax...
    \Session::set('one', array('two' => array('three' =>'value123')));
    $one   = \Session::get('one', 'not one');
    $two   = \Session::get('one.two', 'not two');
    $three = \Session::get('one.two.three', 'not three');
    Debug::dump($one, $two, $three);
    
    Variable #1:
    array(1) {
      ["two"]=>
      array(1) {
        ["three"]=>
        string(8) "value123"
      }
    }
    
    Variable #2:
    array(1) {
      ["three"]=>
      string(8) "value123"
    }
    
    Variable #3:
    string(8) "value123"
    

    Apparently, an individual element in an array cannot be set using dot syntax.
    This code will set a single element with the key 'four.five.six'...
    \Session::set('four.five.six', 'value456');
    $four = \Session::get('four', 'not four');
    $five = \Session::get('four.five', 'not five');
    $six = \Session::get('four.five.six', 'not six');
    Debug::dump($four, $five, $six);
    
    Variable #1:
    string(8) "not four"
    
    Variable #2:
    string(8) "not five"
    
    Variable #3:
    string(8) "value456"
    

    Is this the desired behaviour?
  • Don't want to use the word desired, but it is consistent. All other method (like for example Config and Cache) use dot notation for retrieval only as well. If you want this behaviour, make a feature request for v1.1.
  • Thanks for explaining this, WanWizard.
    I see no need to request this feature as I trust the developers design.

Howdy, Stranger!

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

In this Discussion