Questions tagged [cactivedataprovider]

data provider for Yii PHP based on ActiveRecord

CActiveDataProvider is part of the Yii PHP framework. Excerpt from the v1.1 docs:

CActiveDataProvider provides data in terms of ActiveRecord (AR) objects which are of class modelClass. It uses the AR CActiveRecord::findAll method to retrieve the data from database. The criteria property can be used to specify various query options.

CActiveDataProvider may be used in the following way:

$dataProvider=new CActiveDataProvider('Post', array(
    'criteria'=>array(
        'condition'=>'status=1',
        'order'=>'create_time DESC',
        'with'=>array('author'),
    ),
    'countCriteria'=>array(
        'condition'=>'status=1',
        // 'order' and 'with' clauses have no meaning for the count query
    ),
    'pagination'=>array(
        'pageSize'=>20,
    ),
));
// $dataProvider->getData() will return a list of Post objects

Important Links

API reference

81 questions
1
vote
1 answer

How to access data from a query to a CGridView

I'm trying to use on my view a search made by CreateCommand to fill my CGridView, but I still need to pass as a dataProvider a CActiveDataProvider object. Is there any way to transform my CreateCommand object into CActiveDataProvider or to do the…
1
vote
1 answer

Many-to-many relation in yii2 activedataprovider

I have many-to-many relation with three tables: Category, Product, ProductCategory. Relation in Category: public function getProductCategories() { return $this->hasMany(ProductCategory::className(), ['category_id' => 'id']); } Relation in…
1
vote
1 answer

yii2 create history contract from old id

I'm trying to display a contract history following old id. If an employee create new contract so he is can see the last contract in view history contract. I have tried it but only can display one last contract. if the employee have 2 last contract,…
1
vote
1 answer

Yii. CActiveDataProvider and has many relation

I have two models: Document and Report. One document could have from 0 or several reports. One report belongs to 0 or 1 Document. class Document extends CActiveRecord { public function relations() { return array( 'reports' =>…
Pasha
  • 158
  • 5
1
vote
2 answers

How to do Sorting in CActiveDataProvider in YII?

I write this but it doesn't do any effect in views. $dataProvider=new CActiveDataProvider('Example', array( 'sort'=>array( 'defaultOrder'=>'title ASC', ) )); Is any changes in view needed ?
user6175355
1
vote
1 answer

Yii 1: CActiveDataProvider does not return all records

Here is my CActiveDataProvider query. $startDate='2016-02-28'; $endDate='2016-03-05'; $criteria= new CDbCriteria(); $criteria->with=array('job','job.serviceType'); $criteria->order='t.uploaded_date DESC'; …
Dhara
  • 1,431
  • 4
  • 29
  • 47
1
vote
2 answers

Yii2-activedataprovider doesn't fetch data

I use some $query->andFilterWhere(...) to create my query. and can see the final query by echo $query->createCommand()->rawSql; when I copy the final query and past it on phpmyadmin, 2 record fetched but no result found in ActiveDataProvider. Where…
Masoud Nazari
  • 476
  • 2
  • 6
  • 17
1
vote
2 answers

Yii: Relational CActiveDataProvider does not working, got error "Column not found: 1054 Unknown column"

I'm trying to get data in CActiveDataProvider style in order to pass data to the CGridView in the respective view. I try to get relational data using CActiveData Provider in this way: I have three tables as follows: CREATE TABLE tbl_test_location…
1
vote
1 answer

CGridView filter by year of date

Sorry for long text but my problem is long :-) I made grid like this $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( array( 'name'=>'title', …
Bejkrools
  • 1,129
  • 2
  • 17
  • 38
1
vote
1 answer

yii CDbCriteria select not working?

I need to edit the query of my CGridView so in my model I'm changing the function search() as follow: $criteria=new CDbCriteria; $criteria->select = "links.title, links.url, groups.title as grouptitle"; $criteria->join = " join groups on…
MeV
  • 3,761
  • 11
  • 45
  • 78
1
vote
1 answer

Run function inside CHtml::listData - yii

I am trying to list values from a treview in a dropdown list, in Yii. So, i already have a function to concatenate the treeview in path like (example primary\secondary\terciary. I call this function passing the ID from the data and the function…
1
vote
1 answer

Yii CActiveDataProvider with() and join

I want to have separate row for each related object in CGridView. ModelB has modelAId, so it is HAS_MANY relationship. The following query returns what I am trying to get: select * from modelA a join modelB b on b.modelAId = a.id Here I am getting…
Jamol
  • 3,768
  • 8
  • 45
  • 68
1
vote
0 answers

How setup CActiveDataProvider in YII for many to many plus a third relationship

I have an AR object "league". league is many to many to player via league_has_player lt (which has lt.leauge_id and lt.player_id. I have team is many to many to player via team_has_player A third relation is team which is many to one to league…
1
vote
1 answer

Modelname and its behaviors do not have a method or closure named "getData". in yii

i dont know where am i going wrong i did play round with it but did not achieve anything. i wanna display data using cListview but unable to do so i have a function in model Model public function psearch1() { $name=$_GET['search']; …
user3419342
  • 35
  • 1
  • 8
1
vote
1 answer

CActiveDataProvider with a regular non-database array

I have an array of $items in Yii application which I want to paginate. The array is not related to the database so there's no condition to consider here, just a bunch of defined items that I need to display. So I'm trying to use the…
mmvsbg
  • 3,570
  • 17
  • 52
  • 73