2

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_once inside the admin.php

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.