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.
ThinkPHP
When 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 session
session_start