consume() public method

Reads and deletes a variable from session.
public consume ( string $name ) : mixed
$name string The key to read and remove (or a path as sent to Hash.extract).
return mixed The value of the session variable, null if session not available, session not started, or provided name not found in the session.
Example #1
0
 /**
  * Test consuming session data.
  *
  * @return void
  */
 public function testConsume()
 {
     $session = new Session();
     $session->write('Some.string', 'value');
     $session->write('Some.array', ['key1' => 'value1', 'key2' => 'value2']);
     $this->assertEquals('value', $session->read('Some.string'));
     $value = $session->consume('Some.string');
     $this->assertEquals('value', $value);
     $this->assertFalse($session->check('Some.string'));
     $value = $session->consume('');
     $this->assertNull($value);
     $value = $session->consume(null);
     $this->assertNull($value);
     $value = $session->consume('Some.array');
     $expected = ['key1' => 'value1', 'key2' => 'value2'];
     $this->assertEquals($expected, $value);
     $this->assertFalse($session->check('Some.array'));
 }
 /**
  * Used to read and delete a session values for a key.
  *
  * In your controller: $this->Session->consume('Controller.sessKey');
  *
  * @param string $name the name of the session key you want to read
  * @return mixed value from the session vars
  */
 public function consume($name)
 {
     return $this->_session->consume($name);
 }