TP frame cannot get to the session to ask Daniel to answer

Source: Internet
Author: User
I'm using a new version of TP 3.2.3. I have multiple methods in the same controller, I wrote a session in Method 1, why can't I read it in Method 2? To ask for explanation .....

The code is simple enough to write a controller that inherits controllers. Then there are 2 methods written in it, and the first method writes a session. The second method reads the session. Grammar is the session ("KKK", 999); The other is the direct echo session ("KKK"); The result is reading the session that cannot be read.

Reply content:

I'm using a new version of TP 3.2.3. I have multiple methods in the same controller, I wrote a session in Method 1, why can't I read it in Method 2? To ask for explanation .....

The code is simple enough to write a controller that inherits controllers. Then there are 2 methods written in it, and the first method writes a session. The second method reads the session. Grammar is the session ("KKK", 999); The other is the direct echo session ("KKK"); The result is reading the session that cannot be read.

ThinkPHPWhen the application is initialized, in the ThinkPHP\\Library\\Think\\App.class.php class, if the current running environment cli is not, it is automatically registered from the configuration file session_start ,

The default configuration file ThinkPHP\\Conf\\convention.php is set, that is SESSION_AUTO_START TRUE , the default will automatically open the session, the main check whether your profile overrides this configuration item, the thinkphp configuration file load user-defined will override the default,

Default user-defined profile Application\\Common\\Conf\\config.php , check whether it will be SESSION_AUTO_START set to False or 0

If you do not want to modify the configuration file, just call Session_Start before the method starts


  
   show('.........');    }    public function test()    {        //若配置文件SESSION_AUTO_START为false, 则调用session方法时都学要手动开启session        session_start();        session('xxxxx', 'wodelaojia');    }    public function test2()    {        session_start();                echo session('xxxxx');    }}

Configured SESSION_AUTO_START for TRUE or when in use sessionsession_start

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.