Codeigniter controller inherits the problem instance analysis and codeigniter controller. Codeigniter controller inheritance example analysis, codeigniter controller this article describes the Codeigniter controller inheritance problem. For your reference, the Codeigniter controller inherits the problem instance analysis and codeigniter controller
This article describes the issue of controller inheritance of Codeigniter. We will share this with you for your reference. The details are as follows:
This is often used in projects. in the background, each page must determine the Session to determine whether the user is logged in. in Codeigniter, each controller inherits a public controller.
For example, AdminBase is the public controller of the application background. in each application background controller, it inherits the public AdminBase, but it must also be ensured that AdminBase inherits the CI_Controller.
The same applies to HomeBase at the front end.
The specific implementation is very simple. you only need to create MY_Controller.php under application/core, as shown below:
(MY _ is configurable. in the application/config. php file, locate this item: $ config ['subclass _ prefix'] = 'My _';)
class MY_Controller extends CI_Controller{function __construct(){parent::__construct();}}class AdminBase extends MY_Controller{function __construct(){parent::__construct();......}......}class HomeBase extends MY_Controller{function __construct(){parent::__construct();......}......}
The controllers in application/controllers can be inherited, such as in application/controllers/admin/blog. php.
class Blog extends AdminBase{function __construct(){parent::__construct();......}......}