How can I return just an array of all IDs of a model, e.g:
Town::model()->getIds();
returns:
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
)
How can I return just an array of all IDs of a model, e.g:
Town::model()->getIds();
returns:
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
)
// Model class.
public function getIds()
{
$criteria = new CDbCriteria;
$criteria->select = 'id';
$data = $this->commandBuilder->createFindCommand($this->tableSchema, $criteria)->queryAll();
$ids = array();
foreach ($data as $row)
$ids[] = $row['id'];
return $ids;
}
You can also use CListData