我在数据库中有一个表由(id,sort,parent,title)组成,其中parent是integer。我想通过Yii框架返回父代等于0的记录。我考虑过使用findAllByAttributes,但我不明白:)。我有这个
<?php $model = Father::model()->findByPk(1);
$items[] = $model->getListed(); // note that the [] is important, otherwise CMenu will crash.
$this->widget('application.extensions.CDropDownMenu',array(
'items'=>$items,
)); ?>
有什么帮助吗?
您可以通过以下三种方式获取记录:
使用findAll()
$model=Father::model()->findAll('parent= :id',array(':id'=>0));
使用条件
$criteria=new CDbCriteria();
$criteria->select='*';
$criteria->condition='parent=:id';
$criteria->params=array(':id'=>0);
$model=Father::model()->findAll($criteria);
使用查询生成器
$model= Yii::app()->db->createCommand()
->select('*')
->from('Father')
->where('parent= :id',array(':id'=>0))
->queryAll();
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句