如何迭代数据提供者对象?我想访问返回的每一行的“名称”字段并构建一个列表。你能帮我吗?
表/模型的表结构categories
CREATE TABLE IF NOT EXISTS `categories` (
`idCategory` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
PRIMARY KEY (`idCategory`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=55 ;
*我的控制器类别中的功能*
$names = array();
public function returnCategoryNames()
{
$dataProvider= new CActiveDataProvider('Categories');
$dataProvider->setPagination(false);
$count = $dataProvider->totalItemCount();
for($i = 0; $i < $count; $i++){
// this is where I am lost...
$myname = $dataProvider->data[$i]->name;
array_push($names, $myname);
}
return $names;
}