我是YII 1的初学者,我正在尝试在我的YII应用程序中使用网格搜索,但我的网格搜索无效。请帮助我。 提前致谢。
viewSurveyList.php
<?php $this->pageTitle=Yii::app()->name . ' - Survey Data'; ?>
<div id="innercontent" style="padding-top:30px;">
<h1><?php echo SURVEYLISTHEADTITLE; ?></h1>
<div class="row-button-right">
<?php echo CHtml::button('New Survey',array('type'=>'submit','submit'=>array('site/createSurvey')));?>
</div>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'servey-list',
'dataProvider' => $modelSurvey->search(),
'filter' => $modelSurvey,
'pager'=>array('header'=>'','prevPageLabel'=>'Previous','nextPageLabel'=>'Next','maxButtonCount'=>SHOWNUMBEROFPAGENUMBER ),
'pagerCssClass'=>'pagination',
'emptyText'=>'No Survey Found',
'template' => "{items}\n{summary}\n{pager}",
'columns'=>array(
array(
'header'=>'Name',
'name'=>'Name',
'value' => '$data->Name',
'headerHtmlOptions'=>array('width'=>'80%','valign'=>'middle','align'=>'center'),
'htmlOptions'=>array('width'=>'80%','valign'=>'top','align'=>'left'),
'filter'=>CHtml::activeTextField($modelSurvey,'Name',array('placeholder'=>'Survey Name')),
),
array(
'header'=>'Action',
'name'=>'Action',
'value' => function($data){ echo Survey::model()->getActionLink($data); },
'headerHtmlOptions'=>array('width'=>'20%','valign'=>'middle','align'=>'center'),
'htmlOptions'=>array('width'=>'20%','valign'=>'top','align'=>'left'),
'filter'=>CHtml::link('Clear Filters',array('site/surveyList'),array('title'=>'Clear Filters')),
),
),
));
?>
</div>
Model Survey.php
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
print_r($this);
$criteria=new CDbCriteria;
$criteria->compare('ID',$this->ID);
$criteria->compare('Name',$this->Name,true);
//$criteria->compare('IsDeleted',$this->IsDeleted);
$criteria->compare('CreatedOn',$this->CreatedOn,true);
$criteria->compare('LastModifiedOn',$this->LastModifiedOn,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'Pagination' => array('pageSize'=>SETTINGPAGESIZE), // number of rows per page setting
));
}
public function rules()
{
// The following rule is used by search().
return array(
array('ID, Name, CreatedOn, LastModifiedOn,QuestionNumbers', 'safe', 'on'=>'search'),
);
}
来自SiteController.php的动作调用
public function actionSurveyList()
{
$modelSurvey = new Survey('search');
$this->render('viewSurveyList',array('modelSurvey'=>$modelSurvey));
}
答案 0 :(得分:1)
将以下代码放在actionSurveyList方法
中public function actionSurveyList(){
$modelSurvey = new Survey('search');
if(isset($_GET['Survey']))
$modelSurvey->attributes=$_GET['Survey'];
$this->render('viewSurveyList',array('modelSurvey'=>$modelSurvey));
}