Good day! Began to study yii. Faced such a problem. I make an example of a blog on the leadership off. the site also became interested in how to execute a query using this class, in which an alias will be added. For example, the query is executed

SELECT * FROM `tbl_post` 

But if you need

 SELECT * , `author_id` AS 'user' FROM `tbl_post` 

What should I write in the parameters? By default, everything looks like this:

 $dataProvider=new CActiveDataProvider('Post'); 

I searched Google but didn’t find such an example, I’m probably looking bad, tell me who knows, plz)

    1 answer 1

    You can do this:

     $dataProvider=new CActiveDataProvider('Post', array ( 'criteria'=>array( 'select'=>'* , `author_id` AS `user` ', ), )); 

    But in order to make it work it is necessary to add a user attribute in the Post model, i.e.

     class Post extends CActiveRecord { public $user; // далее ваш код //Также атрибут необходимо зделать несохраняемым в базу public function rules() { //ваш код array ( 'user', 'unSafe' ) } } 

    He himself recently began to study this framework (the first one I study) while I like

    • Thank you very much for the answer. I'll try, if it works, I'll mark it as correct. in the meantime, catch a plus) - Barton