I have class MY_Controller extends CI_Controller
和大配置文件部分的通用逻辑,所以我尝试创建class Profile extends MY_Controller
正如我所理解的那样,配置文件部分的通用逻辑和与此部分相关的所有类都应该扩展此配置文件类,但是当我尝试创建class Index extends Profile
我收到一个错误:
Fatal error: Class 'Profile' not found
CodeIgniter 尝试在中找到此类index.php
我正在运行。
我的错误在哪里?或者也许还有另一种更好的方法来标记共同逻辑?
我认为您已将 MY_Controller 放入 /application/core 中,并在配置中设置前缀。
不过,我会谨慎使用索引作为类名。作为 Codeigniter 中的函数/方法,它具有专用的行为。
如果您想扩展该控制器,则需要将这些类放在同一个文件中。
例如。在/应用程序核心中
/* start of php file */
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
}
...
}
class another_controller extends MY_Controller {
public function __construct() {
parent::__construct();
}
...
}
/* end of php file */
在/应用程序/控制器中
class foo extends MY_Controller {
public function __construct() {
parent::__construct();
}
...
}
or
class bar extends another_controller {
public function __construct() {
parent::__construct();
}
...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)