这里我使用CActiveDataProvider通过给出条件传递选定的行,并且在视图中我在CGridView中显示列工作正常但同时我应该提供搜索列我无法提供搜索可以任何一个帮助。这是我的示例代码
public function actionShow($id)
{
$model=new StudentResult('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['StudentResult']))
$model->attributes=$_GET['StudentResult'];
$dataProvider=new CActiveDataProvider('StudentResult', array(
'criteria'=>array(
'condition'=>"profileId=$id",
),
'pagination'=>array(
'pageSize'=>20,
),
));
$this->render('show',array(
'model'=>$model,
'dataProvider' => $dataProvider,
));
}
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'student-result-grid',
'dataProvider'=>$dataProvider,
'filter'=>$model,
'columns'=>array(
'id',
'moduleCode',
'moduleTitle',
'moduleCredits',
'grade',
'creditsObtain',
'semester',
/*
'points',
'profileId',
'createdOn',
'lastModifiedOn',
'lastModifiedBy',
*/
array(
'class'=>'CButtonColumn',
),
),
)); ?>
所以在视图中我通过给出'dataProvider'=&gt;来显示数据$ dataProvider所以值正确显示但是如果我提供'dataProvider'=&gt;则搜索不起作用$模型 - &GT;搜索();整个值正在显示,搜索正在运行
答案 0 :(得分:1)
您可以在此处将所选行传递给所需的操作。
<?php $this->widget('zii.widgets.grid.CGridView', array('id' =>'list-grid',
'dataProvider'=>$dataProvider->search(),
'filter' =>$dataProvider,
'columns'=>array(
'id',
'moduleCode',
'moduleTitle',
'moduleCredits',
'grade',
'creditsObtain',
'semester',
'action'=>array(
'class'=>'CButtonColumn',
'header' => 'Edit',
'template' => '{Edit}',
'buttons' => array(
'Edit' =>array(
'label' => 'Edit',
'imageUrl'=>Yii::app()>request>baseUrl.'path/to/your/image',// you can use other options
'url' => 'Yii::app()->createUrl("/controller/action/id/".someencryption-to-hide-id($data->id))',),
'visible' => TRUE, ),
),
), )); ?>
您的控制器操作如下:
public function actionYourAction() {
$dataProvider = new ModelName('search');
$dataProvider -> unsetAttributes();
// clear any default values
if (isset($_GET['ModelName'])) {
$dataProvider -> attributes = $_GET['ModelName'];
}
$this -> render('viewPage', array('dataProvider' => $dataProvider, ));
}
模型标准将是:
public function search()
{
$criteria -> compare('id', $this -> id);
...
return new CActiveDataProvider($this, array('criteria' => $criteria, ));
}
让我知道我帮你做对了。