CodeIgniter 3上的HMVC无法正常工作 - 获得404

时间:2015-04-10 16:36:21

标签: php codeigniter hmvc

我试图在我的CI 3安装上设置模块化,但似乎无法正常工作。我在"分支"下使用了wire here找到的wiredesignz包。标签

我做的步骤:

  1. 复制MY_Loader& app / core中的MY_Router
  2. 在application / third_party中复制MX文件夹
  3. 在application / development / config.php中复制了这行代码(我已将config.php移到开发文件夹下)

    //设置模块的位置 $ config [' modules_locations'] = array(     APPPATH'模块/' => ' ../../模块/&#39 ;, );

  4. 创建

    应用      - 模块      - 控制器     --- Test.php      - 楷模      - 意见     --- test.php

  5. 和我的Test.php一样

    class Test extends CI_Controller {
    
        function __construct() {
            parent::__construct();
        }
    
        public function index() {
            $this->load->view('test');
        }
    } 
    

    只是检查一下是否正常,但是当我点击浏览器localhost / myapp / test时,我收到404错误。

    任何想法我做错了什么?

5 个答案:

答案 0 :(得分:2)

您是否尝试将控制器和视图放在模块文件夹中的test文件夹中?

意味着类似的东西

应用/模块/测试/控制器/ test.php的

答案 1 :(得分:2)

Codeigniter 3的HMVC Modules文件夹 How to implement HMVC in codeigniter 3.0?

codeigniter 3 hmvc tree reqire files 我测试了作品

答案 2 :(得分:0)

尝试将CI_Controller更改为此MX_Controller

class Test extends MX_Controller {

    function __construct() {
        parent::__construct();
    }

    public function index() {
        $this->load->view('test');
    }
} 

但我认为你还需要子模块文件夹示例

modules => admin => controllers
modules => admin => controllers => Test.php
modules => admin => models
modules => admin => views
modules => admin => views => test.php

确保配置路线

示例:

$route['test'] = "admin/test/index"; 

答案 3 :(得分:0)

在第307行

之后的application / third_party / MX / Loader.php中添加以下行



protected function _ci_object_to_array($object) 
	{
    return is_object($object) ? get_object_vars($object) : $object;
    }




工作正常。

答案 4 :(得分:0)

就我而言,即使文件/文件夹结构正确,以防万一仍然有人遇到这个问题,我花了几天的时间才弄清楚,还有两个其他问题:

  1. 我不是100%确信,但是如果我没记错的话,我看不到子文件夹,因此我不得不再次在其上使用chmod 755
  2. 这是杀手er:我的文件名使用小写字母(“ welcome.php”而不是“ Welcome.php”)作为控制器。用大写字母重命名文件后,我摆脱了404,一切正常。