【问题标题】:hmvc codeigniter routes modules controller functionhmvc codeigniter 路由模块控制器功能
【发布时间】:2013-05-06 15:42:02
【问题描述】:

我有来自https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc的hmvc结构

modules content,创建控制器news_event,并为函数view详细查看 这样的结构

  • 模块
    • ...
    • ...
    • 内容
      • 控制器
        • ...
        • 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

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    如果您使用模块文件夹中的路由文件,则路由名称必须以模块名称开头。

    modules/content/config/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);
    

    【讨论】:

    • 我非常不同意 URL 与系统调用。通过 URL 直接调用模块允许该模块的独立性,这反过来允许更好的隔离。使用系统会强制您对 Module::run 模块进行某种代理。
    猜你喜欢
    • 1970-01-01
    • 2017-04-15
    • 1970-01-01
    • 2012-05-21
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 2015-06-04
    相关资源
    最近更新 更多