Table of Contents
Codeigniter控制器controller继承问题实例分析,codeigniter控制器
您可能感兴趣的文章:
Home php教程 php手册 Codeigniter控制器controller继承问题实例分析,codeigniter控制器

Codeigniter控制器controller继承问题实例分析,codeigniter控制器

Jun 13, 2016 am 08:47 AM
codeigniter controller controller inherit

Codeigniter控制器controller继承问题实例分析,codeigniter控制器

本文实例讲述了Codeigniter控制器controller继承问题。分享给大家供大家参考,具体如下:

在项目中经常用到这样一种情况,后台中每个页面都要判断Session来确定用户是否登陆状态.对于在Codeigniter中,那么就会考虑每个控制器继承一个公用控制器。

比如:AdminBase 为应用后台的公用的控制器,在每一个应用后台控制器里面都来继承公共的AdminBase ,但是同时要确保AdminBase 也是继承CI_Controller的。

前台HomeBase也是同样的道理。

具体实现很简单,只要在application/core下面新建MY_Controller.php,如下
(MY_是可配置的,application/config/config.php 文件并找到这一项:$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();
......
}
......
}

Copy after login

然后在application/controllers里面的控制器就可以继承了,比如application/controllers/admin/blog.php中

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

Copy after login

更多关于CodeIgniter框架相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》

希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

  • MySQL的使用中实现读写分离的教程
  • Yii实现多数据库主从读写分离的方法
  • Thinkphp实现MySQL读写分离操作示例
  • 使用PHP实现Mysql读写分离
  • sql server2005实现数据库读写分离介绍
  • MySQL主从同步、读写分离配置步骤
  • mysql 读写分离(实战篇)
  • mysql 读写分离(基础篇)
  • CodeIgniter配置之SESSION用法实例分析
  • CodeIgniter配置之routes.php用法实例分析
  • CodeIgniter读写分离实现方法详解
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to properly calibrate your Xbox One controller on Windows 11 How to properly calibrate your Xbox One controller on Windows 11 Sep 21, 2023 pm 09:09 PM

Since Windows has become the gaming platform of choice, it's even more important to identify its gaming-oriented features. One of them is the ability to calibrate an Xbox One controller on Windows 11. With built-in manual calibration, you can get rid of drift, random movement, or performance issues and effectively align the X, Y, and Z axes. If the available options don't work, you can always use a third-party Xbox One controller calibration tool. Let’s find out! How do I calibrate my Xbox controller on Windows 11? Before proceeding, make sure you connect your controller to your computer and update your Xbox One controller's drivers. While you're at it, also install any available firmware updates. 1. Use Wind

Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance? Detailed explanation of C++ function inheritance: How to use 'base class pointer' and 'derived class pointer' in inheritance? May 01, 2024 pm 10:27 PM

In function inheritance, use "base class pointer" and "derived class pointer" to understand the inheritance mechanism: when the base class pointer points to the derived class object, upward transformation is performed and only the base class members are accessed. When a derived class pointer points to a base class object, a downward cast is performed (unsafe) and must be used with caution.

Learning Laravel from scratch: Detailed explanation of controller method invocation Learning Laravel from scratch: Detailed explanation of controller method invocation Mar 10, 2024 pm 05:03 PM

Learning Laravel from scratch: Detailed explanation of controller method invocation In the development of Laravel, controller is a very important concept. The controller serves as a bridge between the model and the view, responsible for processing requests from routes and returning corresponding data to the view for display. Methods in controllers can be called by routes. This article will introduce in detail how to write and call methods in controllers, and will provide specific code examples. First, we need to create a controller. You can use the Artisan command line tool to create

How do inheritance and polymorphism affect class coupling in C++? How do inheritance and polymorphism affect class coupling in C++? Jun 05, 2024 pm 02:33 PM

Inheritance and polymorphism affect the coupling of classes: Inheritance increases coupling because the derived class depends on the base class. Polymorphism reduces coupling because objects can respond to messages in a consistent manner through virtual functions and base class pointers. Best practices include using inheritance sparingly, defining public interfaces, avoiding adding data members to base classes, and decoupling classes through dependency injection. A practical example showing how to use polymorphism and dependency injection to reduce coupling in a bank account application.

Detailed explanation of C++ function inheritance: How to debug errors in inheritance? Detailed explanation of C++ function inheritance: How to debug errors in inheritance? May 02, 2024 am 09:54 AM

Inheritance error debugging tips: Ensure correct inheritance relationships. Use the debugger to step through the code and examine variable values. Make sure to use the virtual modifier correctly. Examine the inheritance diamond problem caused by hidden inheritance. Check for unimplemented pure virtual functions in abstract classes.

Packaging technology and application in PHP Packaging technology and application in PHP Oct 12, 2023 pm 01:43 PM

Encapsulation technology and application encapsulation in PHP is an important concept in object-oriented programming. It refers to encapsulating data and operations on data together in order to provide a unified access interface to external programs. In PHP, encapsulation can be achieved through access control modifiers and class definitions. This article will introduce encapsulation technology in PHP and its application scenarios, and provide some specific code examples. 1. Encapsulated access control modifiers In PHP, encapsulation is mainly achieved through access control modifiers. PHP provides three access control modifiers,

Detailed explanation of C++ function inheritance: How to understand the 'is-a' and 'has-a' relationship in inheritance? Detailed explanation of C++ function inheritance: How to understand the 'is-a' and 'has-a' relationship in inheritance? May 02, 2024 am 08:18 AM

Detailed explanation of C++ function inheritance: Master the relationship between "is-a" and "has-a" What is function inheritance? Function inheritance is a technique in C++ that associates methods defined in a derived class with methods defined in a base class. It allows derived classes to access and override methods of the base class, thereby extending the functionality of the base class. "is-a" and "has-a" relationships In function inheritance, the "is-a" relationship means that the derived class is a subtype of the base class, that is, the derived class "inherits" the characteristics and behavior of the base class. The "has-a" relationship means that the derived class contains a reference or pointer to the base class object, that is, the derived class "owns" the base class object. SyntaxThe following is the syntax for how to implement function inheritance: classDerivedClass:pu

Laravel Study Guide: Best Practices for Controller Method Calls Laravel Study Guide: Best Practices for Controller Method Calls Mar 11, 2024 am 08:27 AM

In the Laravel learning guide, calling controller methods is a very important topic. Controllers act as a bridge between routing and models and play a vital role in the application. This article will introduce the best practices for controller method calling and provide specific code examples to help readers better understand. First, let's understand the basic structure of controller methods. In Laravel, controller classes are usually stored in the app/Http/Controllers directory. Each controller class contains multiple

See all articles