Kohana 3扩展模块模型文件结构

发布于 2024-10-08 20:25:33 字数 734 浏览 3 评论 0原文

我有一些由管理员和公共模型使用的代码。目前一些方法是完全相同的,但存储在管理和公共部分的单独模型中。我创建了一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

短暂陪伴 2024-10-15 20:25:33
// modules/common/classes/model/common/post.php
Model_Common_Post extends Model {}

// ADMIN/application/classes/model/admin/post.php
Model_Admin_Post extends Model_Common_Post {}

// PUBLIC/application/classes/model/post.php
Model_Post extends Model_Common_Post {}

因此,您的公共和管理模型应放置在其应用程序目录中,并且公共文件(common_post 模型)位于公共模块中。

// modules/common/classes/model/common/post.php
Model_Common_Post extends Model {}

// ADMIN/application/classes/model/admin/post.php
Model_Admin_Post extends Model_Common_Post {}

// PUBLIC/application/classes/model/post.php
Model_Post extends Model_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文