Pergunta

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?

Foi útil?

Solução

// 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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top