Yii DataProvider】的更多相关文章

1,DataProvider 什么是数据提供者 数据提供者可以获取数据,并提供给其他组件或页面使用 可以获得列的数据进行分页和排序 经常用来给数据小部件提供数据,方便用户互动地进行数据的分页与排序 实现了yii\data\DataProviderInterface接口类 示例: dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 5, ], 'sort' =&…
1.main.php增加导航栏严格区分大小写,否则会出现404错误 2.增加'分页'功能---前后台的models里面的search.php 添加 public function search($params)    {        $query = Study::find();        // add conditions that should always apply here        $dataProvider = new ActiveDataProvider([      …
最近在研究PHP的Yii框架,很喜欢,碰到导出Excel的问题,研究了一下,就有了下面的方法: 1.首先在config\main.php中添加对PHPExcel的引用,我的方式是这样: 1 2 3 4 5 6 7 8 // autoloading model and component classes     'import'=>array(                         'application.models.*',         'application.componen…
当你需要在一个GridView渲染某一个复杂元素的时候(特别是在这种情况下,这是一个小部件),这就需要你在控制器中调用一个动作.例如你给一个GridView的定义这样的一列: <?php $this->widget('bootstrap.widgets.TbGridView', array(    'id' => 'folder-grid',    'dataProvider' => $model->search($folder_id),    'template' =>…
一种方法是使用CPagination处理翻页需要的数据如:总数据项数,每页数据项数,当前页,然后在视图中使用CBasePager来绘制. 控制器动作的代码示范: function actionIndex(){ $criteria = new CDbCriteria(); $count=Article::model()->count($criteria); $pages=new CPagination($count); // results per page $pages->pageSize=1…
加入 关联表 相关字段的搜索: 先说一句,我们在这里仅仅谈 "一对多" 的关联搜索,首先,不要忘了我们的数据库,忘记的同学请戳这里:这里.能够看到在 tbl_post 中是有一个外键关联到 tbl_user 表的,用以查找作者的相关信息.建了数据库之后,看看我们生成的 Yii 代码的 POST 的 Model. 里面的 realtion 例如以下(忽略 comment 的): /** * @return array relational rules. */ public functio…
CArrayDataProvider类手册: http://www.yiichina.com/api/CArrayDataProvider 在yii中无论是CListView还是CGridView,对应数据的传值都是从后台完成的,有时候我们不是从数据库读取,而是自定义一些数组来作为表格的数据.其实Yii在后台对应数组处理有2个好函数的,一个是CActiveDataProvider,另外一个是CArrayDataProvider.从英文的字面意思很容易理解,CActiveDataProvider是…
相关类手册: http://www.yiichina.com/api/CButtonColumn   buttons 属性 public array $buttons; the configuration for additional buttons. Each array element specifies a single button which has the following format: 'buttonID' => array( 'label'=>'...', // text…
然用过Yii做了一个小项目了,但是过程中间解决的问题没有随手记下来,导致新项目开始后,以前碰到的问题还得在查一遍,干脆就记下来,以便不时之需. 有新的会随时更新. 1.如何显示ActiveRecord执行的sql语句: array( 'class'=>'CFileLogRoute', 'levels'=>'trace,error, warning', ), // uncomment the following to show log messages on web pages /* array…