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
8
votes
1 answer

MySql Pivot table in to Yii CActiveDataProvider

I have a table structure as following: CREATE TABLE IF NOT EXISTS `CustomValue` ( `id` int(11) NOT NULL, `customFieldId` int(11) NOT NULL, `relatedId` int(11) NOT NULL, `fieldValue` text COLLATE utf8_unicode_ci, `createdAt` timestamp NOT…
dev1234
  • 5,376
  • 15
  • 56
  • 115
6
votes
5 answers

Yii pagination showing fewer items than available

I have a simple CGridView that is fed from a CActiveDataProvider. At the moment, and I'm not sure how long this has been happening, it does not show all the data items in the view with pagenation enabled. My header shows "Displaying 1-7 of 9…
Poco
  • 91
  • 1
  • 6
4
votes
1 answer

how to limit query for ActiveDataProvider?

I am trying to make a query to get the first 10 records for example, and pass it to the ActiveDataProvider. The query is working fine and returning the required number of records only, while the ActiveDataProvider is printing all the records, here…
Mohammad
  • 3,449
  • 6
  • 48
  • 75
3
votes
1 answer

Yii 1, get SQL generated by CDbCriteria

got a problem, I need to get all ids of models (not only visible but all models) in CGridView. For that I use its DataProvider - get a criteria from it and pass it to command builder $criteria = $dataProvider->getCriteria(); $criteria->select =…
Link Link
  • 81
  • 2
  • 8
3
votes
1 answer

Yii1 CGridView(Yii-Booster): How to change filter key(filterVal) in TbGridView(based on CGridView)?

I am using yii-booster(4.0.1) TbGridView(extends CGridView) and need to change the filter variable name in _REQUEST($_POST, $_GET) for filter function. In my grid, I have filter functionality and when I press enter after entering some words in the…
3
votes
1 answer

Yii CActiveDataProvider query caching not working correctly

I want to cache the DB results for a CActiveDataProvider instance. I prepare the data provider in a controller's action, and then I use the data provider in a CGridView, later in some view. I used to have this code: $cars=new CActiveDataProvider( …
G_Gus
  • 150
  • 2
  • 7
2
votes
2 answers

Yii Criteria->with without relation or without 'on'

How to create criteria->with() witout "on" or without "default relation" in query? select * from status kk inner join user tt left join userstatus ii on kk.status_id = ii.status_id and ii.user_id = tt.user_id I want use it for CGridView…
2
votes
2 answers

Yii Class CActiveDataProvider not found

I'm new to Yii, and I'm getting this error "Class 'app\controllers\CActiveDataProvider' not found" while running a widget. This is my code: models/industrial.php:
user3640056
  • 732
  • 4
  • 13
  • 28
2
votes
1 answer

yii CActiveDataProvider Multiple Table Join

I'm working on a magazine site right now and I'm having trouble with getting Yii to return all data with CActiveDataProvider. The SQL query runs fine when run through SQL, and I receive no errors in Yii when it's run. Checking logs, the whole SQL…
Martin
  • 21
  • 2
2
votes
1 answer

Yii CActiveDataProvider data is not loading from joined tables

My code : $criteria = new CDbCriteria(); // $criteria->select = array("id"); $criteria->with = array('userProfiles'=>array( 'select'=>'firstname' )); $criteria->together = true; $criteria->condition = "firstname like '%$q%' " . "and…
Shahid Karimi
  • 4,096
  • 17
  • 62
  • 104
2
votes
1 answer

Can CArrayDataProvider be used as a data source with exportablegridbehavior?

ExportableGridBehavior - tinyurl.com/expgrid This works fantastically with usual dataproviders. But when using with CArrayDataProvider it is causing issues, and giving blank data in the CSV. Is it possible to use this extension with a…
marooned
  • 51
  • 7
2
votes
1 answer

Yii How to Cache in CActiveDataProvider

I want to cache the DB results for a CActiveDataProvider instance. that no caches CActiveDataProvider? or all of it works fine? I prepare the data provider in a controller's action, and then I use the data provider in a CGridView, later in some…
Botir Ziyatov
  • 508
  • 1
  • 6
  • 20
2
votes
1 answer

Yii access previous data item from within a CListView partial

I'm using CActiveDataProvider and CListView to output a list of names. I want to bold the name using html only when the name is the same as the name directly previous to it. These are not identical rows in the database, only the 'name' attribute is…
James
  • 118
  • 1
  • 10
1
vote
1 answer

get multiple docs by ID as ActiveRecord in Yii2 from ealstic search using mget()

I'm using the Yii2 class yii\elasticsearch\ActiveRecord to recieve data from elastic search. Usually methods in this class for getting data from elastic will return that data as ActiveRecord (AR) object. So it's easy, to create an activeDataProvider…
The Bndr
  • 13,204
  • 16
  • 68
  • 107
1
vote
0 answers

How to sort encrypted database fields using CActiveDataProvider

$criteria->order = 'patient_admit_details.first_name DESC'; $criteria->group = 'Patients.patient_id'; $dataProvider = new CActiveDataProvider('Patients', array('criteria'=>$criteria)); The patient's first name and last name were stored in the…
Lakshman
  • 47
  • 7
1
2 3 4 5 6