Using Yii, how can I get an array from an Active Record.
Say something like this:
array('foo', 'bar', 'lala')
From something like this:
MyTable::model()->findall()
Using Yii, how can I get an array from an Active Record.
Say something like this:
array('foo', 'bar', 'lala')
From something like this:
MyTable::model()->findall()
ActiveRecord class has an attribute called attributes. You can find its description here: http://www.yiiframework.com/doc/api/1.1/CActiveRecord#attributes-detail.
In order to get all attributes in an array, use this:
$var = $model->attributes;
You could also do something like
which returns an array of all country names, or
which returns an array of all country ids.
Use the Yii2 ArrayHelper by including to your controller this will convert a model data to an associated array
If i understand you correctly:
It will give you array id => name
Don't use ActiveRecord. Use
CDBCommand->queryColumn()
Use Chtml to this is a Ugly Hack! Apply this solution is the better way to this that I found:
You can add this code to an ActiveRecord class, e.g.:
And, use this way:
You can read more about in this link.