Home >Backend Development >PHP Tutorial >CI 变量名与控制器名一样 怎么处理

CI 变量名与控制器名一样 怎么处理

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:16:581208browse

core/ MY_Controller.php

<code>class MY_Controller extends CI_Controller {

    protected $user;
}
</code>

controllers/User.php

<code>class User extends MY_Controller {
    
    public function index() {
        
        var_dump($this->user); //null
    }
}</code>

CI 里面这个怎么破,有没有什么标识?

回复内容:

core/ MY_Controller.php

<code>class MY_Controller extends CI_Controller {

    protected $user;
}
</code>

controllers/User.php

<code>class User extends MY_Controller {
    
    public function index() {
        
        var_dump($this->user); //null
    }
}</code>

CI 里面这个怎么破,有没有什么标识?

$this->user 是调用 MY_Controller 中的 $user 属性,跟你的 User Controller 没有一毛钱关系!

这样写有什么问题吗?如果有,请详细说明你的问题,不要含糊不清!

这应该是不会冲突的,你有什么具体问题可以说说。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn