Home >Backend Development >PHP Tutorial >Why can't subclasses inherit from parent classes?
Outputecho session('name')
Nothing is displayed. I use {$Think.session.name}
in the test template and it cannot be output. Why is this?
<code><?php namespace Home\Controller; use Think\Controller; class CommonController extends Controller{ public function __initialize(){ session('name','tom'); } } ?> <?php namespace Home\Controller; use Think\Controller; class TestController extends CommonController{ public function test(){ echo session('name'); $this->display(); } } ?></code>
Outputecho session('name')
Nothing is displayed. I use {$Think.session.name}
in the test template and it cannot be output. Why is this?
<code><?php namespace Home\Controller; use Think\Controller; class CommonController extends Controller{ public function __initialize(){ session('name','tom'); } } ?> <?php namespace Home\Controller; use Think\Controller; class TestController extends CommonController{ public function test(){ echo session('name'); $this->display(); } } ?></code>
I remember that the initialization method is _ (underscore)
The initialization method is an _ (underscore). I misunderstood it. If the subclass has an initialization function, you must indicate whether the initialization of the parent class is executed. If the initialization of the parent class is not executed automatically.