I’m wondering where to store buisness logic in Yii MVC structure.
For example i want to have an "interface" (not php term) to get an user.
Should i do a static method in my User model ? and then call "self::model()->findByPk($userId);" ?
This approach will make this file huge, it contains validation data, relations, labels, custom methods like "getFullName" that concat first and last names, and then added to this buisness logics methods ?
I’m just asking for a separated Model in fact, where all access to Database are made.
C is your interface where V sees through and M represents your data which could be asked from C and presents to V for user to enjoy from browser.
in Yii world, all the hard work accessing data and managing relationships have been done via ActiveRecord model which you inherit from when you build your own data model.
if you check any examples of model (check yii demo), you will notice that in model you deal with more ‘definitions’ rather than actual code. you define validation rules, you define relations etc. all the hard work and generic repeating work has been done by yii activerecord model.
so thin C, fat M, clean V, if you feel M is too fat there must be something wrong imho or if you have to, you could manage them in separated files combine using include or Yii::import at runtime.
well, if you don’t like whatever yii default activerecord provids or it does not meet your need, you definitely could wrap up CActiveRecord creating your own version of base class on top of CActiveRecord by adding more generic functions then inherit it in all your data model.
it’s up to the nature of your requirement about data model, if it’s really something generic yii should have, you may want to suggest yii dev team in yii 2.0 feature request forum.