zoukankan      html  css  js  c++  java
  • yii1的后台分页和列表

    控制器:

    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>
     
     
  • 相关阅读:
    PHP的后期静态绑定
    php的clone 浅拷贝
    python 从文件导入分类
    Yii2 主从 数据库
    什么是 jsonp ?
    为speedphp最新版添加 仿Yii 的简易版 数据验证 支持不同场景,自定义回调
    redis入门指南-安装redis
    composer -vvv
    依赖注入
    yii2-user
  • 原文地址:https://www.cnblogs.com/fpcing/p/9947575.html
Copyright © 2011-2022 走看看