简体   繁体   English

CakePHP:如何注册会话?

[英]CakePHP: how to register the session?

In PHP5, the code: session_register(""); 在PHP5中,代码: session_register("");

my code: 我的代码:

function login() {
        // Don't show the error message if no data has been submitted.  
        $this->set('error', false);

        // Production mode. No output. For AJAX
        Configure::write('debug', 0);

        // Does not render the view
        // Others method : $this->render(false, false);
        $this->autoRender = false;

        // The most important : set : debug = 0 and register session
        session_register("");

            $this->Session->write('test',"test1");

                echo $this->Session->read('test');
        }
        return ;
    }

This code is outdated since 2001-2002 该代码自2001-2002年以来已过时

To store the data in the session you should use: 要将数据存储在会话中,您应该使用:

$this->Session->write('name', 'value');

To get the data stored in the session use: 要获取存储在会话中的数据,请使用:

$data = $this->Session->read('name');

Where name is the session variable name 其中name是会话变量名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM