0

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

在 Session 中存储/检索数据

从控制器、视图或任何其他扩展 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?
            }
        }
    }
4

1 回答 1

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");
        }
    }
}
于 2012-11-05T12:40:28.283 回答