2013-07-04 88 views
2

我在CodeIgniter HMVC中设置了两个模块。一个是模板,另一个是测试。从CodeIgniter中的另一个模块加载控制器HMVC

这里的文件夹结构..

  1. 模板
    • 控制器
      • home.php
    • -----
      • ----。 php
    • 视图
      • 布局
        • admin.php的
        • main.php
        • user.php的
    • home.php
  2. 测试 个
    • 控制器
      • test.php的

我在routes.php文件哪些路由home.php作为模板的默认控制器增加了一个路线变量。并自动加载模板库。

现在,当我访问http://mysite.com/templates/home/indexhttp://mysite.com/templates/ ..它工作正常,但是当我运行另一个模块(测试)它显示错误。我也试过echo Modules::run('templates/home/index');但同样的问题。我有流动的代码在测试。PHP

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Test extends MX_Controller { 


    public function index() 
    { 
     $this->load->module('templates'); 
     $this->templates->index(); 

    } 
} 

它说Unable to load the requested file: home.php

这里是我的模板库

<?php 

if (!defined('BASEPATH')) 
    exit('No direct script access allowed'); 

class Template { 

    private $template_data = array(); 
    private $headers = array(); 
    private $CI; 

    public function __construct() { 
     $this->CI =& get_instance(); 
     $this->CI->config->load('template'); 
    } 

    function set($name, $value) { 
     $this->template_data[$name] = $value; 
    } 

    function add_header($header) { 
     array_push($this->headers, $header); 
    } 

    function load($template = '', $view = '', $view_data = array(), $return = FALSE) { 
     $this->CI = & get_instance(); 
     $this->set('contents', $this->CI->load->view($view, $view_data, TRUE)); 
     $this->set('headers', implode('', $this->headers)); 
     return $this->CI->load->view($template, $this->template_data, $return); 
    } 

} 

/* End of file Template.php */ 
/* Location: ./system/application/libraries/Template.php */ 

回答

4

看来,该模块可以在不指定控制器名称只有当控制器名称的模块名称匹配加载

控制器可以加载编辑为其他控制器的类变量 使用$ this-> load-> module('module/controller');或简单地 $ this-> load-> module('module');如果控制器名称的 模块名称匹配

https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/overview

尝试加载这样的模块:

$this->load->module('templates/home'); 
相关问题