netstu netstu - 4 months ago 9
PHP Question

doc has error , i'm not sure

http://docs.phalconphp.com/en/0.6.0/reference/session.html

Storing/Retrieving data in Session

From a controller, a view or any other component thats extends Phalcon\DI\Injectable you can access the session service and store items and retrieve them in the following way:

<?php
class UserController extends Phalcon\Mvc\Controller
{
public function indexAction()
{
//Set a session variable
$this->session->set("user-name", "Michael");
}

public function welcomeAction()
{

//Check if the variable is defined
if ($this->session->has("user-name")) {

//Retrieve its value
$name = $this->session->set("user-name"); //here, set or get?
}
}
}

Answer

You are correct. That was supposed to be a get (for retrieving records). The corrected example is:

http://docs.phalconphp.com/en/latest/reference/session.html

<?php

class UserController extends Phalcon\Mvc\Controller
{

    public function indexAction()
    {
        //Set a session variable
        $this->session->set("user-name", "Michael");
    }

    public function welcomeAction()
    {

        //Check if the variable is defined
        if ($this->session->has("user-name")) 
        {

            //Retrieve its value
            $name = $this->session->get("user-name");
        }
    }
}