2013-05-12 119 views
0

我有HMVC結構從https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvcHMVC笨路由模塊控制器功能

模塊內容,創建控制器news_event,以及用於功能視圖詳細視圖 結構這樣

  • 模塊
    • ...
    • ...
    • 內容
      • 控制器
        • ...
        • news_event.php

news_event。PHP

我有3個功能,索引,視圖和頁面

function index() { $this->pages(); } 

function pages($_pages = 1){ ... } 

function view($_id_uri = false){ ... } 

我已經成功做出

http://example.com/ci_hmvc/content/news_event/

成爲

http://example.com/ci_hmvc/news_event/

,但它的錯誤,當它的負載下一個視圖

http://example.com/ci_hmvc/news_event/view/my-var-uri-friendly-here

我得到404錯誤,但如果我用這個URL調用,成功

http://example.com/ci_hmvc/content/news_event/view/my-var-uri-friendly-here

我的路由代碼是

$route['news_event'] = 'content/news_event'; 
$route['news_event/(:any)'] = 'content/news_event/view/$1'; 

怎樣的路線,如果我想如果您使用路由文件從模塊文件夾內的

http://example.com/ci_hmvc/news_event/view/my-var-uri-friendly-here

或本

http://example.com/ci_hmvc/news_event/my-var-uri-friendly-here

回答

1

訪問時,路由名稱必須以模塊名稱開頭。

模塊/內容/配置/ routes.php文件

$route['default_controller'] = 'content'; 

$route['content/'] = ''; 

你可以在正常的路由文件添加路由

的application/config/routes.php文件

$route['news_event'] = 'content/content/news_event'; 

hmvc背後的想法是不是致電一個模塊通過路由方法,而是在系統內部調用模塊本身(視圖或控制器)

Modules::run('module/controller/method', $args); 
+1

我很尊重URL和系統調用的不同意見。通過URL調用模塊直接允許該模塊的獨立性,作爲回報,允許更好的隔離。使用系統迫使你有一些代理模塊::運行模塊。 – koxon 2014-08-02 21:39:35