1
我有以下几点:
public function search() {
$criteria = new CDbCriteria();
$criteria->compare('id',$this->id);
$criteria->compare('entity_id',$this->entity_id);
$criteria->compare('name',$this->name,true);
(etc...)
if (Yii::app()->user->role == SiteUser::ROLE_AUTHOR) {
$userId = Yii::app()->user->getId();
$entity = Entity::model()->find("user_id = $userId");
$criteria->condition = 'entity_id=:entity_id';
$criteria->params = array(':entity_id'=>$entity->id);
}
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
当我将此:
if (Yii::app()->user->role == SiteUser::ROLE_AUTHOR) {
$userId = Yii::app()->user->getId();
$entity = Entity::model()->find("user_id = $userId");
$criteria->condition = 'entity_id=:entity_id';
$criteria->params = array(':entity_id'=>$entity->id);
}
用户只能在CGridView 看到的是自己的记录。尼斯。 但是,由于某些原因,过滤器不起作用。
如果我评论的那些行:
$criteria->condition = 'entity_id=:entity_id';
$criteria->params = array(':entity_id'=>$entity->id);
过滤器的工作原理。但是,显然,用户将看到所有用户记录。
更新: 如果不是使用条件和PARAMS性能我用compare()
方法,像这样:
$criteria->compare('entity_id',$entity->id);
它的工作原理。
它为什么会与比较,而不是条件和参数?