【问题标题】:codeIgniter - Load controller from other location if exists else use normal locationcodeIgniter - 如果存在,则从其他位置加载控制器,否则使用正常位置
【发布时间】:2013-12-15 22:12:22
【问题描述】:

我在使用 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; }
}
?>

【问题讨论】:

  • 您可能需要hmvc 用于 CI。有一段时间没有使用 CI,但允许 MVC 设计模式,从不同的控制器调用控制器/视图和附加组件,所有这些都是 imo

标签: php codeigniter frameworks


【解决方案1】:

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

在文件夹 core 中我终于编辑了以下文件。

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多