项目结构并在所有模块控制器下共享var
我有以下结构:
modules/group
modules/group/modules/forum
modules/group/modules/gallery
modules/group/modules/events
这是构建组的正确方法吗?还是更好
modules/group
modules/group/controllers/ForumController.php
modules/group/controllers/GalleryController.php
modules/group/controllers/EventsController.php
另一个问题。我需要组模块下的所有操作控制器中的组对象,并且我不想在所有控制器中编写以下代码
$group = Group::model()->findByPk($_GET['idgroup']);
网址如下:
/group/<idgroup>/forum/<idforum>
/group/<idgroup>/gallery/<idgallery>
执行此操作的正确方法是什么?
I have the following structure:
modules/group
modules/group/modules/forum
modules/group/modules/gallery
modules/group/modules/events
Is this a correct way of structuring groups? or is better
modules/group
modules/group/controllers/ForumController.php
modules/group/controllers/GalleryController.php
modules/group/controllers/EventsController.php
And another question. I need group object in all actions controllers under group module and i dont want to write the following code in all controllers
$group = Group::model()->findByPk($_GET['idgroup']);
The url's like:
/group/<idgroup>/forum/<idforum>
/group/<idgroup>/gallery/<idgallery>
What is the right way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案取决于几个因素:
如果有上述任何一个,那么是的,将它们放入自己的模块中是有意义的。否则,最好将它们添加到
group
模块中。根据 Yii 文档:
关于将组对象添加到所有控制器操作,通常我会为我的模块添加一个基本控制器类(类似于
/group/components/GroupController.php
)并扩展该控制器而不是我所有控制器中的基础控制器。GroupController
应该扩展 Yii 的CController
并包含您希望从模块控制器访问的组对象。The answer depends on a couple things:
If any of the above, then yes, it would make sense to put them into their own modules. Otherwise, adding them to the
group
module would be preferred.According to Yii documentation:
In regards to the adding the group object to all controller actions, generally I'll add a base Controller class for my module (something like
/group/components/GroupController.php
) and extend that controller rather than the base one in all of my controllers.GroupController
should extend Yii'sCController
and contain the group object that you want to have accessible from your module's controllers.