开发者

Codeigniter cannot extend controller

开发者 https://www.devze.com 2023-03-14 13:21 出处:网络
I have created an admin controller that extends the blog controller (both are located in application/controller). However, when I tried to access the controller, it gives me an error that the blog con

I have created an admin controller that extends the blog controller (both are located in application/controller). However, when I tried to access the controller, it gives me an error that the blog controller was not found. If I put require_once(APPPATH.'controllers/blog.php'); inside the admin.php file it works. But I'm just wondering if there's another possible way to extends the blog controller without having to use require_onc开发者_StackOverflow社区e inside the admin.php


From CI user guide

If you are extending the Controller core class, then be sure to extend your new class in your application controller's constructors.

class Welcome extends MY_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->view('welcome_message');
    } 

}

That means your Blog controller must extends CI_Controller

Example:

class MY_Blog extends CI_Controller {

    function hello() {
        $data = 'something';
    }
}

class Admin extends MY_Blog {

    function do_something() {}
}

Userguide

0

精彩评论

暂无评论...
验证码 换一张
取 消