Home  >  Article  >  Backend Development  >  Codeigniter controller controller inheritance problem example analysis, codeigniter controller_PHP tutorial

Codeigniter controller controller inheritance problem example analysis, codeigniter controller_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:00:221043browse

Codeigniter controller controller inheritance problem example analysis, codeigniter controller

This article describes the Codeigniter controller controller inheritance problem with an example. Share it with everyone for your reference, the details are as follows:

In projects, there is often a situation where each page in the background must judge the Session to determine whether the user is logged in. For Codeigniter, each controller will be considered to inherit a common controller.

For example: AdminBase is the public controller of the application background. Each application background controller inherits the public AdminBase, but at the same time, make sure that AdminBase also inherits CI_Controller.

The same is true for HomeBase at the front desk.

The specific implementation is very simple, just create a new MY_Controller.php under application/core, as follows
(MY_ is configurable, go to application/config/config.php file and find 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();
......
}
......
}

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

class Blog extends AdminBase
{
function __construct()
{
parent::__construct();
......
}
......
}

Readers who are interested in more content related to the CodeIgniter framework can check out the special topic on this site: "Introduction to codeigniter tutorial"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

Articles you may be interested in:

  • Tutorial on implementing read-write separation in the use of MySQL
  • Yii’s method of implementing master-slave read-write separation in multiple databases
  • Thinkphp implements MySQL read-write separation operation example
  • Use PHP to implement Mysql read-write separation
  • Introduction to sql server2005 database read-write separation
  • MySQL master-slave synchronization, read-write Separation configuration steps
  • mysql read-write separation (practical part)
  • mysql read-write separation (basic part)
  • CodeIgniter configuration SESSION usage example analysis
  • CodeIgniter configuration routes.php usage example analysis
  • CodeIgniter read-write separation implementation method detailed explanation

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1093702.htmlTechArticleCodeigniter controller controller inheritance problem example analysis, codeigniter controller This article tells the example of Codeigniter controller controller inheritance problem. Share it with everyone for your reference, specifically...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn