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
0
votes
2 answers

How to use WHERE in yii2 joinWith() that is doing eager loading

I have tables: document and document_content. One document can have many contents. I am using joinWith() method to get data from document_content table together with document using model relations. The queries executed are these : SELECT document.*…
offline
  • 1,589
  • 1
  • 21
  • 42
0
votes
1 answer

CActiveDataProvider doesnt give selected columns

$criteria->select = 't.*,count(business_unit.id) as TotalBusinessUnits,count(users.id) as TotalUsers ,count(positions.id) as TotalPositions, count(skills.id) as TotalSkills , users.first_name , users.last_name, count(question_bank.id) as…
Haseeb Ahmad
  • 7,914
  • 12
  • 55
  • 133
0
votes
1 answer

How to get join attributes in CDbCriteria in YII?

In company model I get joining models user and business_unit. $criteria=new CDbCriteria; $criteria->compare('id',$this->id); $criteria->compare('status',$this->status); $criteria->condition = "`t`.status = '1'"; $criteria->order = 'created…
Haseeb Ahmad
  • 7,914
  • 12
  • 55
  • 133
0
votes
1 answer

Second table value not showing in view while Using CActiveDataProvider and CdbCriteria used together in yii

I have two tables, tables names and fields are listed below company(tbl_id,sales_id,user_id,assigned_on) users(user_id,user_name) I want to execute the following query SELECT assigned_on,u.user_name FROM company c LEFT JOIN users u ON…
Leo
  • 31
  • 8
0
votes
1 answer

yii dataprovider returns error 500

I tried defining the dataprovider for CGridView in yii but am getting this error 500: Trying to get property of non-object the following are my model and view/admin.php code snippets model.php: public function search2() { $sql='select…
0
votes
1 answer

Collect data from three table in yii1?

I am new in YII1. I have three tables: Jd, jda and user. Relation with jd and jda is 'jobDescription'=> array(self::HAS_MANY, 'JobDescriptionAssignment', /*array('id'=>'job_desc_id')*/'id'), and the relation between jda and user is 'users' =>…
Mohibul Hasan Rana
  • 237
  • 2
  • 3
  • 16
0
votes
1 answer

CActiveDataProvider using relations accessing foreign key data from another table

I have a relatively simple setup using Yii application but I'm struggling to access data across tables in the following scenario: Two tables: payments_info (id, data): where id is the primary auto increment key, model class name PaymentInfo payments…
mmvsbg
  • 3,570
  • 17
  • 52
  • 73
0
votes
1 answer

Yii cgridview cactivedataprovider doesnt work properly

I configured the Yii cactivedataprovider as the documentation writes: $criteria = new CDbCriteria(); $criteria->together = true; $criteria->with = array( 'relationId0', 'relationId1', ...…
Gábor Varga
  • 840
  • 5
  • 15
  • 25
0
votes
1 answer

ArrayDataProvider edit value in GridView

In my code i want to edit values. I try $model but it's work only in ActiveDataProvider. When i use $data problem is the same - result is 0. $dataProvider, 'tableOptions' => ['class' =>…
Cliassi
  • 81
  • 3
  • 10
0
votes
2 answers

Undefined Variable $data in CActiveDataProvider - Yii Framework

I want to fetch data from my table using CActiveDataProvider in Yii. Everything seems to be working well but when I want to display the data from another related table using relations, I get an error. 'Undefined variable $data'. here is my admin.php…
Richie
  • 1,398
  • 1
  • 19
  • 36
0
votes
1 answer

yii2 ActiveDataProvider in combination with ActiveForm?

I'm trying to use an ActiveDataProvider as the source for my ActiveDataForm. However I am unable to access the information. Not from within the view or the controller. How ever the diseaseList + ListView is working. I can't seem to figure out where…
Wijnand
  • 1,192
  • 4
  • 16
  • 28
0
votes
1 answer

yii apply sort to CActiveDataProvider

I am trying to apply sort from remember filters on my admin function i have if (isset($_GET[ucfirst($this->id) .'_sort'])) { $extractSort = $_GET[ucfirst($this->id) .'_sort']; //Yii::log($extractSort); …
shorif2000
  • 2,582
  • 12
  • 65
  • 137
0
votes
1 answer

Yii CActiveDataProvider Relations

Anyone can enighten me, i am new to Yii. I have 3 tables projects (id,name,status,created_by) users (id,name) project_users (id,project_id,user_id) The condition is: Show all projects if created by current user or current user is a…
Jon Fabian
  • 286
  • 2
  • 15
0
votes
1 answer

How to access sub-objects of Yii relational query

A table Product contains has_many relationship with a table **Slab** that further contains has_many relationship with a table Rate. A relational query is wrapped inside CActiveDataProvider that joins three tables across certain parameters and return…
0
votes
1 answer

Get model attributes values from CActiveDataProvider in Yii

I have zii.widgets.grid.CGridView and I applied to it a CActiveDataProvider from different model, for example: In the users model I used zii.widgets.grid.CGridView to display the articles that the user created, so when the user clicks on view,…
MD.MD
  • 708
  • 4
  • 14
  • 34