带 HMVC 的 Kohana 儿童控制器
我有一个主控制器,我想使用 HMVC 从该控制器调用子控制器。我设置了一条规则,将参数路由到特定操作,该操作通过主控制器的“Request::factory”调用子控制器,但由于无限循环,它不起作用。有什么办法可以做到吗?
我必须使用 HMVC,因为主控制器向子控制器发送一些信息,所以我需要一个控制层。
它将是一种 CMS 增删改查应用程序的插件。
主控制器:http://pastebin.com/nt2fhMEy
子控制器示例:http://pastebin.com/WqaHZaxf
路线:http://pastebin.com/6JGFf2i2 (我还没有配置 caction 和 cid。)
额外注意:它将是我的 CMS 的 CRUD 模块。主控制器将加载主模板和一些配置。主控制器还包含一些 ORM 函数,子控制器必须能够使用parent::functionname。子控制器位于 cruds/ 目录中,cms 会自动创建它们。
I have a main controller and I want to call child controllers from this controller with HMVC. I setted a rule that routes parameter to a specific action that calls children controllers with "Request::factory" for the main controller but it didn't work because of infinity loop. is there any way to do it?
I must use HMVC because main controller sends some information to children controller so I need a controlling layer.
It will be kind of a plugin for crud applications for a CMS.
The main controller: http://pastebin.com/nt2fhMEy
An example of child controller: http://pastebin.com/WqaHZaxf
Route: http://pastebin.com/6JGFf2i2 (I didn't configure caction and cid yet.)
Extra Note: It will be kind of a crud module for my CMS. The main controller will load main template and some configs. Also the main controller includes some ORM functions and children controller must be able to use parent::functionname. The children controllers are in cruds/ directory and the cms creates them automatically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您对控制器和 HMVC 的看法存在一些错误。
最好的方法是使用面向对象的控制器。我的意思是“子控制器”需要扩展主控制器。
让主控制器扩展Controller_Template,子控制器扩展主控制器。
当您通过路由向子控制器发送请求时,您不仅可以访问父属性,而且您的请求将执行以下操作:
从我从你的问题中得到的信息来看,你根本不需要 HMVC。实际上,这是一种非常糟糕的数据传递模式。请记住,当您通过 HMVC 执行内部请求时,这实际上是一个全新的请求。它将再次检查路线和此列表。您将无权访问之前的所有请求属性。
另一个提示:不要将 ORM 函数放在主控制器中。请改用实际的 ORM 模型。
You have a few mistakes in your idea of the controllers and HMVC.
The best way to do so is to use object oriented controllers. By this I mean the "child controllers" need to extend the main controller.
Let the main controllers extend Controller_Template and the child controllers extend the main controller.
When you send requests to child controllers through routes you will not only have access to the parent properties, but your request will do the following:
From what I get from your question you will not need HMVC at all. Actually it's a very bad pattern for passing data. Keep in mind that when you perform an internal request through HMVC this is actually a completely new request. It will go through the routes and this list again. You will not have access to all of the previous request properties.
Another tip: don't put ORM functions in the main controller. Use the actual ORM models instead.