Kohana 3扩展模块模型文件结构
我有一些由管理员和公共模型使用的代码。目前一些方法是完全相同的,但存储在管理和公共部分的单独模型中。我创建了一个名为 common 的模块,我想通过从通用模型扩展管理和公共模型来存储共享代码。我只是对设置它的结构感到困惑。假设我有:
Model_Post extends Model
Model_Admin_Post extends Model
结构应该是这样的:
modules/common/classes/model/common/post.php
Model_Post extends Model_Common_Post
或者
modules/common/classes/common/model/post.php
Model_Post extends Common_Model_Post
或者
modules/common/classes/model/post/common.php
Model_Post extends Model_Post_Common
我已经看了一些模块,它似乎有所不同,那么这真的取决于你想要如何构建它吗?我注意到 auth 模块,这是一个官方模块,似乎遵循第一个示例,但我不太确定。尽管使用第二种或第三种方法似乎更容易,因为您只需将模块名称附加到开头或结尾即可。从长远来看,我认为最好遵循“正确”的方式来保持一致性。如果有的话,哪一个是正确的?
I have some code that is used both by the admin and public models. Currently some of the methods are exactly the same, but stored in the separate models of the admin and public sections. I created a module called common and I want to store shared pieces of code there by having the admin and public models extend from the common model. I'm just confused on the structure to set it up. Assuming I have:
Model_Post extends Model
Model_Admin_Post extends Model
Should the structure be like:
modules/common/classes/model/common/post.php
Model_Post extends Model_Common_Post
or
modules/common/classes/common/model/post.php
Model_Post extends Common_Model_Post
or
modules/common/classes/model/post/common.php
Model_Post extends Model_Post_Common
I've tooken a look at a few modules and it seems to vary, so is it really just up to how you feel like structuring it? I noticed the auth module, which is an official module seems to follow the first example, but I'm not too sure. Although it seems easier to use the 2nd or 3rd way as you just tack on the module name to the beginning or end instead. In the long run I think it'd be better to follow the "correct" way for consistency. Which of these would be correct, if at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您的公共和管理模型应放置在其应用程序目录中,并且公共文件(common_post 模型)位于公共模块中。
So, your public and admin models should be placed in their applications dirs, and common files (common_post model) is in common module.