Reputation: 7750
I've inherited a medium-size website written with a custom (small) php framework. I want to switch to the yii framework but first I need to find a solution for the following problem : the site is basically a series of courses and exercices that are available in multiple languages. In fact all the content is available in multiple languages.
The users can select their preferred language and the localized content is retrieved from the database.
Database organisation :
How can this be easily integrated with the "Post::model()->findAll()" yii's way of retrieving data from the DB ?
Should I write my custom derived class of CModel that would retrieve language preference from the IUserIdentity class and adapt the query ? Is there some code arround that I could look at ?
Upvotes: 1
Views: 2273
Reputation: 13394
Should I write my custom derived class of CModel that would retrieve language preference from the IUserIdentity class and adapt the query ?
I don't think, you need to do that. There are different ways:
1.) You can use the cdbcriteria to set the criteria (for example the where clause) after creation an instance of the object and before running findAll http://www.yiiframework.com/doc/guide/1.1/en/database.ar (look at the end of the 2nd quarter of the page)
2.) An other way is to overwrite the findAll inside your model:
public function findAll($condition='',$params=array())
{ $condition["criteria"]->compare ....
return parent::findAll($condition,$params);
}
3.) You also can use the onBeforFind trigger http://www.yiiframework.com/doc/api/1.1/CActiveRecord#onBeforeFind-detail, which fires before (every) the findAll search
i would prefer that 1st or 2nd idea.
Upvotes: 1