How to iterate over a dataprovider object? I want to access the \'name\' field of each row returned and build a list. Can you help?
Table structure for table
Try this:
public function returnCategoryNames()
{
$dataProvider= new CActiveDataProvider('Categories');
$dataProvider->setPagination(false);
//$count = $dataProvider->totalItemCount();
$names = array();
foreach($dataProvider->getData() as $record) {
$names[] = $record->name;
}
return array_unique($names);
}
However you dont need to use a data provider, instead just use the model
foreach(Categories::model()->findAll() as $record) {