【发布时间】:2016-05-10 14:21:24
【问题描述】:
想知道是否有人可以提供帮助。
我的 Yii 应用程序中有两个页面使用相同的控制器/模型,但使用不同的模型功能。我的初始页面是非常标准的“管理”页面,它使用默认的 search() 作为模型(这工作正常 - 包括过滤),但我随后做了一个辅助视图/动作,它查看一个改变的搜索功能 - 这有传递给它的 ID(从 URL 参数中提取)。这工作正常,但页面中的过滤器不起作用,这很烦人。
我认为这是因为在控制器中,我没有正确传递 ID 变量???
这是我的一些代码;
型号:
public function searchByEvent($event_id) {
$criteria = new CDbCriteria;
$criteria->compare('id', $this->id, true);
$criteria->compare('event_id', $this->event_id, true);
$criteria->compare('status_id', $this->status_id, true);
$criteria->compare('checkin_status_id', $this->checkin_status_id, true);
$criteria->compare('guest_of_user_id', $this->guest_of_user_id, true);
$criteria->compare('user_id', $this->user_id, true);
$criteria->compare('assign_group', $this->assign_group, true);
$criteria->with = 'user';
$criteria->compare('user.forename', $this->user_forename, true);
$criteria->compare('user.surname', $this->user_surname, true);
$criteria->compare('user.company', $this->user_company, true);
$criteria->order = 'user.surname ASC';
$criteria->condition = "event_id = :event_id";
$criteria->params=(array(':event_id'=>$event_id));
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination'=>array('pageSize'=>50),
));
}
控制器:
public function actionAdminByEvent() {
$model = new EventAttendees('searchByEvent');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['EventAttendees']))
$model->attributes = $_GET['EventAttendees'];
$this->render('webroot.themes.'.Yii::app()->name.'.views.adminEventAttend.adminByEvent', array(
'model' => $model,
));
}
查看;
$event_id = Yii::app()->getRequest()->getParam('event_id');
this->widget('booster.widgets.TbGridView', array(
'id' => 'event-attendees-grid',
'dataProvider' => $model->searchByEvent($event_id),
'pager' => array(
'class' => 'booster.widgets.TbPager',
'displayFirstAndLast' => true,
),
'filter' => $model,
'template'=>'{summary}{pager}{items}{pager}',
'selectableRows' => 0,
'selectionChanged' => 'function(id){ location.href = "' . $this->createUrl('view') . '/id/"+$.fn.yiiGridView.getSelection(id);}',
'columns' => array(...
谁能看到我的过滤器哪里出错了,或者我是否错过了搜索步骤?
【问题讨论】:
-
请更新您的问题并向我们展示您的模型中的规则方法是什么样的