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

时间:2013-12-15 22:12:22

标签: php codeigniter frameworks

我遇到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; }
}
?>

1 个答案:

答案 0 :(得分:0)

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

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

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

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

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