yii1的後臺分頁和列表
阿新 • • 發佈:2018-11-12
控制器:
public function actionIndex()
{
$model = new Cases('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Cases'])) $model->attributes = $_GET['Cases'];
$this->render('index', ['model' => $model]);
}
model:
public function rules()
{
return array(
array('title', 'required'),
array('course_type', 'safe'),
// The following rule is used by search().
array('title', 'safe', 'on' => 'search'), //這個是用來搜尋用的
);
}
public function search($act='')
{
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('title',$this->title,true);
$criteria->compare('time',$this->time,true);
$criteria->compare('course_type',$this->course_type,true);
if($act == 'list') $this->status = 1;
if($act == 'recycle') $this->status = 0;
$criteria->compare('status',$this->status);
$criteria->order = ' id DESC ';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
檢視:
<div class="tab-pane active" id="list">
<?php
$this->widget ( 'zii.widgets.grid.CGridView', array (
'id' => 'users-grid-list',
'dataProvider' => $model->search('list'),
'filter' => $model,
'columns' => array (
'title',
array (
'name' => 'course_type',
'value' => array (
$this,
'getCourse'
),
'filter' => $course_list
),
)
) );
?>
</div>