Function CodeIgniter-多个控制器中提供的功能
我对CodeIgniter比较陌生,到目前为止,我的项目完全是使用控制器和视图创建的。然而,随着它变得越来越复杂,我发现有些函数是我复制粘贴到多个控制器中的——这并不理想,因为编辑一个控制器需要记住编辑所有其他的控制器 有太多我一无所知的CI特性-模型、助手、扩展“控制器”等等。为了完成上述任务,我应该去哪里?我想我也可以直接Function CodeIgniter-多个控制器中提供的功能,function,codeigniter,controller,Function,Codeigniter,Controller,我对CodeIgniter比较陌生,到目前为止,我的项目完全是使用控制器和视图创建的。然而,随着它变得越来越复杂,我发现有些函数是我复制粘贴到多个控制器中的——这并不理想,因为编辑一个控制器需要记住编辑所有其他的控制器 有太多我一无所知的CI特性-模型、助手、扩展“控制器”等等。为了完成上述任务,我应该去哪里?我想我也可以直接import()一块代码,尽管我感觉这不是“CodeIgniter方式” 将所有“实用程序”功能放入“助手管理器”并访问该管理器 或创建一个基本控制器,并从中扩展其他控制器
import()
一块代码,尽管我感觉这不是“CodeIgniter方式” 将所有“实用程序”功能放入“助手管理器”并访问该管理器
或创建一个基本控制器,并从中扩展其他控制器
我相信Phil Sturgeon对此有一个指导:base\u controller.php
<?php
class Base_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
}
function base_function(){
}
}
?>
<?php
require_once('base_controller.php');
class Other_Controller extends Base_Controller{
function __construct()
{
parent::__construct();
}
function index()
{
$this->base_function();
}
}
?>
other_controller.php
<?php
class Base_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
}
function base_function(){
}
}
?>
<?php
require_once('base_controller.php');
class Other_Controller extends Base_Controller{
function __construct()
{
parent::__construct();
}
function index()
{
$this->base_function();
}
}
?>
谢谢您的链接。这篇文章没有提到如何创建我自己的助手。它是否像在helpers文件夹中创建一个不以“MY_”开头的文件一样简单?如果加载两个具有相同函数名的Helper,会发生什么情况?调用时将执行哪个函数?您应该扩展具有相同函数名的“Helper”(即MY_array_Helper.php)。如果您不这样做,我不确定,但它很可能会调用PHP中最后定义的方法