开发者

PHP splitting models based for related tables

I develop most of my apps using CodeIgniter, there is no strict MVC. Generally, I just create models based on database tables or controllers. However, I have two tables 'campaigns' and 'ads' that are related to one another. So often, there will be "Get Ads By Campaign" and so forth. Would you just create a campaign model and use that for everything? or create one for campaigns and one for ads and anything that uses 'ads' generally use the ads model?

Just looking for suggestions on keeping things organized. Thank you!

EDIT:

Or, I could extend the 'Ads' model from the campaign model, so I always use $this->campaign_model referen开发者_Go百科ce ?


I would do one for each and add convenience methods like getAds on the Campaign model and the corresponding ones on the Ad model.


It is the matter of isolation. Each model should be designed to do its specific job. It may not sound useful for now but in the long run it will be useful if you later decide to introduce additional task in ads but not in campaigns or vice versa.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜