3

hmvc のセットアップがあり、正常に動作しています。

私はギャラリーモジュールを持っています。

ギャラリー モジュールは 3 つのコントローラーに分割され、その構造は次のとおりです。

/modules/gallery/
/modules/gallery/config/
/modules/gallery/helpers/
/modules/gallery/controllers/
/modules/gallery/controllers/gallery.php
/modules/gallery/controllers/galleries.php
/modules/gallery/controllers/images.php
/modules/gallery/models/
/modules/gallery/models/galleriesmodel.php
/modules/gallery/models/imagesmodel.php
/modules/gallery/views/dashboard.tpl
/modules/gallery/views/galleries/dashboard.tpl
/modules/gallery/views/images/dashboard.tpl

とにかく、私は自分のimages.phpコントローラー内に関数を持っていますlist_items


だから私はURL http://example.com/gallery/images/listhttp://example.com/gallery/images/list_itemsにマップしたい

だから私は、その/modules/gallery/config/routes.php中にルートを追加するだけだと思った。

しかし、ルートは含まれていないようです。

からのルート/application/config/routes.phpが含まれておりdie('loaded')、モジュールに a を配置するとroutes.php、スクリプトが強制終了されます。

しかし、実行中

print_r($this->router)コントローラの 1 つから、モジュールからのルートが表示されませんroutes.php

何が起きてる?

4

2 に答える 2

1

私の知る限りでは、

HMVC は、異なる階層モデルを使用して、各モジュール内で要求されたコントローラーのみを検索しますが、モジュール内で routes.php を使用したルート オーバーライドは決して読み取られません。

それを調べて、モジュール内を探すMX_Router::locateことはありません。routes.php

また、構成フォルダーCI_Router::_set_routingで検索するものをオーバーライドしません。routes.php

モジュールのルート オーバーライドを機能させるには、使用可能なすべてのモジュールをオーバーライドCI_Router::_set_routingして読み込む必要があります。config/router.php

于 2012-10-04T06:52:50.237 に答える
0

ブロンチャが道を示し、コードを示します。私はこのソリューションを使用します:

MY_Router クラス ( ) 内でこのメソッドを (より適切に)編集または拡張する必要があり_set_routing()ます。system/core/Router.phpthird_party/Router.php

これで、常にロードされるはずmodule/config/routes.phpです... (140行目あたりです)

// Load the routes.php file.
        if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/routes.php'))
        {
            include(APPPATH.'config/'.ENVIRONMENT.'/routes.php');
        }
        elseif (is_file(APPPATH.'config/routes.php'))
        {
            include(APPPATH.'config/routes.php');
        }

        // Include routes every modules
        $modules_locations = config_item('modules_locations') ? config_item('modules_locations') : FALSE;
        if(!$modules_locations)
        {
            $modules_locations = APPPATH . 'modules/';
            if(is_dir($modules_locations))
            {
                $modules_locations = array($modules_locations => '../modules/');
            }
            else
            {
                show_error('Modules directory not found');
            }
        }
        foreach ($modules_locations as $key => $value)
        {
            if ($handle = opendir($key))
            {
                while (false !== ($entry = readdir($handle)))
                {
                    if ($entry != "." && $entry != "..")
                    {
                        if(is_dir($key.$entry))
                        {
                            $rfile = Modules::find('routes'.EXT, $entry, 'config/');
                            if($rfile[0])
                            {
                                include($rfile[0].$rfile[1]);
                            }
                        }
                    }
                }
                closedir($handle);
            }
        } 

        $this->routes = ( ! isset($route) OR ! is_array($route)) ? array() : $route;
        unset($route);

それが役立つことを願っています...

于 2015-01-05T13:08:00.483 に答える