我编辑了标准my model->搜索功能,仅查看具有相同businessID的数据,但现在高级搜索不起作用。
以下是我在模型上的代码 - > search()
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('LOVEAGENT_ID', $this->LOVEAGENT_ID);
$criteria->compare('FIRST_NAME', $this->FIRST_NAME, true);
$criteria->compare('LAST_NAME', $this->LAST_NAME, true);
$criteria->compare('DOB', $this->DOB, true);
$criteria->compare('PASSWORD', $this->PASSWORD, true);
............
$criteria->condition = 'BUSINESS_ID=:businessID';
$criteria->params = array(':businessID' => Yii::app()->user->businessId);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
我的管理员控制器:
public function actionAdmin() {
$model = new LoveAgentContactDetails('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['LoveAgentContactDetails'])) {
$model->attributes = $_GET['LoveAgentContactDetails'];
}
$this->render('admin', array(
'model' => $model,
));
}
视图中的和Cgrid视图设置:
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'love-agent-contact-details-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'FIRST_NAME',
'LAST_NAME',
'lastLoginTime',
'created',
array(
'class' => 'CButtonColumn',
),
),
));
答案 0 :(得分:3)
问题在这里
$criteria->condition = 'BUSINESS_ID=:businessID';
通过这种方式,您可以重新考虑先前准备的条件。您可以使用CDbCriteria::addCondition
,但最好的方法是
$criteria->compare('BUSINESS_ID',Yii::app()->user->businessId);