简体   繁体   English

CodeIgniter:对HMVC和Views有些怀疑

[英]CodeIgniter: some doubts about HMVC and Views

I've just discovered HMVC Modular Extension for CodeIgniter https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home and it seems perfect for my needs but I have some question. 我刚刚发现了针对CodeIgniter的HMVC模块化扩展https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home ,它看起来非常适合我的需求,但我有一些问题。

Let's say I have two controllers: 假设我有两个控制器:

  • Site which is the main controller and is used to show site's pages and may call methods of Users controller for example to show a form 站点是主控制器,用于显示站点的页面,可以调用用户控制器的方法,例如显示表单
  • User controller is used to authenticate users, to show login/sign up forms... 用户控制器用于验证用户,显示登录/注册表单...

Now I have these questions: 现在我有这些问题:

  1. If the user access the User controller directly (mysite.com/user/method) I want to show a full page while if i load a method of User from within the Site controller I want to show only a form (for example), is this possible? 如果用户直接访问用户控制器 (mysite.com/user/method)我想显示一个完整的页面,如果我从站点控制器中加载一个User的方法我想只显示一个表单(例如),是这可能吗?
  2. What happens to view of a module loaded from another module: is the view shown automatically or i need to show it manually and how does the view behave? 查看从另一个模块加载的模块会发生什么:是自动显示的视图还是需要手动显示的视图以及视图的行为方式?

If you method is being called via Modules::run() 如果通过Modules :: run()调用方法

There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. 第三个可选参数允许您更改函数的行为,以便将数据作为字符串返回,而不是将其发送到浏览器。

Eg: 例如:

//put underscore in front to prevent uri access to this method.
public function _module1()
{
     $this->load->view('partial_view', array('some data'=>'some data'), TRUE)
}

call it inside your SITE view easily 轻松地在您的SITE视图中调用它

Modules::run('User/_module1')
// should show whatever is in partial_view ie: a form

//an alternative is to pass in any params if the method requires them
Modules::run('User/_module1', $param)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM