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

WBOY
Release: 2016-06-06 20:16:58
Original
1161 people have browsed it

core/ MY_Controller.php

<code>class MY_Controller extends CI_Controller {

    protected $user;
}
</code>
Copy after login
Copy after login

controllers/User.php

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

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

回复内容:

core/ MY_Controller.php

<code>class MY_Controller extends CI_Controller {

    protected $user;
}
</code>
Copy after login
Copy after login

controllers/User.php

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

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

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

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template