How to select and use with an alias?


I have a table with two fields for two languages:



I want to select the field, according to the language and this works fine:

$criteria->select = "code,text_$lang,active";

What I would like to do is select the field with an alias and then use that alias to return the value, somthing like this:

$criteria->select = "codigo,text_$lang as text,activo";




echo CHtml::encode($model->text)

But it doesn’t work, I get an error saying “Property “menu.text” is not defined.” (menu is the model)

Is it possible to do what I want?


Just add this property to your model:

class Menu extends CActiveRecord


    public $text;


Or it can be protected, but then you’ll need a getter and a setter.


Thank you!