Example analysis of CodeIgniter controller controller inheritance Problem _php example

Source: Internet
Author: User
Tags codeigniter

The example of this article describes the CodeIgniter controller controller inheritance problem. Share to everyone for your reference, specific as follows:

In the project often used in such a situation, in the background of each page to determine whether the user login status. For CodeIgniter, it is considered that each controller inherits a public controller.

For example: Adminbase for the application background of the common controller, in each application background controller to inherit the public adminbase, but also to ensure that Adminbase also inherit Ci_controller.

The same is true for the front desk homebase.

The implementation is very simple, as long as the Application/core under the new my_controller.php, as follows
(My_ is configurable, application/config/config.php files and finds this: $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 ();
......
}
......
}

Then the controller inside the application/controllers can be inherited, such as the application/controllers/admin/blog.php

Class Blog extends Adminbase
{
function __construct ()
{
parent::__construct ();
......
}
......
}

More about the CodeIgniter framework interested readers can view the site topic: "CodeIgniter Introductory Course"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.