codeIgniter-从其他位置加载控制器,如果存在,则使用正常位置


codeIgniter - Load controller from other location if exists else use normal location

我对codeIgniter有问题,找不到答案。我想做的是建立一个CMS,用一个管理系统来管理多个站点。我有标准的类和函数,但有时一个站点比另一个站点工作,所以我需要专门为该站点更改控制器。

我现在的问题是,我不知道如何更改自动加载控制器/模型,并查看它在自己的文件夹中的第一个位置(如果存在的话)。如果存在,则从自己的文件夹加载文件,否则使用全局文件。

在其他方面,我需要这个。

控制器新闻(http://mywebsite.com/news/在目录中。自己的文件夹是/home/user/domains/website/public_html/codeIgniter/controllers全局文件夹是/home/libs/codeIgniter/controllers

全局文件夹设置在网站的index.php设置中。

首先,它需要检查第一个文件中的文件。如果不存在,请使用全局文件。我希望你能帮助我。

我添加了一个几乎相同的代码,但随后添加了视图控制器,然后它是另一个函数。我也想做一个标准函数,这样我就不需要使用标准函数以外的其他函数。

谢谢。

<?php
/* !DESCRIPTION: This method behaves the same as the default $this->load->view() except it allows you to
include files outside your root application view folder. It will change the path, include the file, 
then change the path back to the original. Nice to have when using shared templates over multiple sites.
*/
//!VAR -> $path :: The absolute path to the view folder (IE: /var/shared/codeigniter/views/)
//!VAR -> $view :: The view file name (IE: shared-header)
//!VAR -> $data :: The variables and values you wish to pass to the view, if any (Defaults to empty array())
//!VAR -> $return :: Set to TRUE if you want to return the value rather than add to the view (Defaults to FALSE)
function external_view($path, $view, $data=array(), $return=FALSE)
{
    $__ci =& get_instance();
    $op = $__ci->load->_ci_view_path;
    $__ci->load->_ci_view_path = $path;
    $v = $__ci->load->view($view, $data, $return);
    $__ci->load->_ci_view_path = $op;
    if ($return === TRUE) { return $v; }
}
?>

我找到了自己的答案。这是一次很好的搜索。我搜索了codeIgniter核心文件夹中的每个文件,并创建了一个新的常量APPPATH_OWN,通过视图、控制器模型等的每个函数,我创建了一种函数,首先检查OWN路径文件,而不是正常的路径文件。

在文件夹核心中,我终于编辑了以下文件。

Router.php
Common.php
Config.php
CodeIgniter.php
Loader.php

在文件夹数据库中,我更改了DB.php文件夹。

我曾希望有一个更简单的解决方案。