duanshanduo3363 2013-06-16 22:38
浏览 25
已采纳

HMVC模式 - 所有三元组M-V-C如何共享相同的视图模板/ css / etc.

How do all the different modules (or packages or however you call them) composed of models-controllers-views share the same site design (template, includes like header and footer, assets like css, js, etc.) in a HMVC architecture as all the triads have their own View folder ?

  • 写回答

1条回答 默认 最新

  • douba7784 2013-06-18 23:31
    关注

    You really don't want modules to share the same views. Typically what you want is a common view, the outer view. In HMVC the controller is the middle man between the view and the model. All requests will be routed to a controller action. Your initial request could be to a controller that instantiates a view (outer view), then within that same controller you make a request to a module controller which gives a view as a response. The initial controller takes the module controllers view response and sets it to a section of the outer view.

    Class Controller_Page extends Controller {
    /**
    *Initial controller
    */
    public function action_index() {
      //get the outer controller view
      $outerView = View::factory('outermost');
      //request to a module called widget
      $widgetView = Request::factory('widget');
      //add the widget to the body of the outer view
      $outerView->body = $widgetView;
      $this->response->body($outerView);
      }
    }
    
    Class Controller_Widget extents Controller {
    /**
    *Module Controller
    */
    public function action_index() {
       $view = View::factory('widget');
       //set the widget view as the response
       $this->response->body($view);
       }
    }
    
    //contents of "outermost" view
    <html>
    <body>
    <!--The $body property was binded to the view by the contoller ("$outerView->body") -->
    <!-- Binding of properties to views is how data is passed to the view -->
    <?php echo $body; ?>
    </body>
    </html>
    
    //contents of "widget" view
    <p>
    I'm a widget
    </p>
    
    //the final result will be
    <html>
    <body>
    <p>I'm a widget</p>
    </body>
    </html>
    

    Also note that in HMVC there is a Model, View, and Controller but it's not the "MVC architecture" you hear talked about. It more follows the Presentation Abstraction Control (PAC) architecture. In the MVC architecture the model notifies the view of changes, this is not the case with PAC.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab