doc有错误,我不确定

时间:2012-11-05 11:08:26

标签: php phalcon

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

在会话

中存储/检索数据

从控制器,视图或任何其他扩展Phalcon \ DI \ Injectable的组件,您可以访问会话服务并存储项目并按以下方式检索它们:

<?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?
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

你是对的。那应该是get(用于检索记录)。更正后的例子是:

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");
        }
    }
}