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

How to insert data into objects iterated by Yii CActiveDataProvider

I have a strange request and I'm not sure there is a better way other than simply brute force, but I have a CActiveDataProvider being rendered and virtual properties of the underlying Model are being used. I would like to be able to pass extra…
Poco
  • 91
  • 1
  • 6
1
vote
2 answers

Process in CActiveDataProvider or CGridView

I have a table called City, table contain field IsMetro it is bit(1), so it can store 1 or 0, i have generated model for this table and generated CRUD operation forms. Now i want True instead of 1 and False instead of 0. Where should i perform this…
Hitesh Modha
  • 2,740
  • 5
  • 28
  • 47
1
vote
1 answer

Yii CActiveDataProvider Order and Pagination

I am trying to get all model item using CActiveDataProvider in Yii. These items are sorted by rand() and a pagination of 20 is applied. Here's my code: $i = new CActiveDataProvider('Item', array( 'criteria' => array( …
HermannHH
  • 1,732
  • 1
  • 27
  • 57
1
vote
1 answer

Yii data provider pagination how to make human url?

I am setting the pagination variable with the following: $dp->pagination = array('pageVar'=>'page'); And adding to the main config rule with this: '/myrule/page/' => 'controller/action' URLs /myrule/page/1 and /myrule/?page=1 work.…
1
vote
1 answer

Yii with join using CDbCriteria and CActiveDataProvider with custom Search

Hi I am using Yii to create an Application I have modified the search() in model and I have come up with a problem. Users can log in as admins, managers, clients When a user is logged as a manager, he can view clients only from the store they both…
1
vote
2 answers

Foreach through a large table using Yii ActiveRecord - "out of memory" errors

I have a website on Yii Framework and I want to search a table for matching words. I keep getting "out of memory" (it is a large table). I try this code but it keeps loading the page $dataProvider = new CActiveDataProvider('Data'); $iterator = new…
Swissa Yaakov
  • 186
  • 3
  • 15
1
vote
1 answer

Yii CactiveDataProvider multiple table join?

I'm trying to join 3 tables in a CActiveDataProvider to help me order things fully and better. But I'm struggling to get the arrangement down properly. I've put comments to try and help outline what i'm after. I can do it in SQL fine, but i'd like…
Jonnny
  • 4,939
  • 11
  • 63
  • 93
1
vote
1 answer

How to set current page with Yii's CActiveDataProvider?

I've created this CActiveDataProvider: $dataProvider=new CActiveDataProvider('Post',array( 'criteria'=>array( 'condition'=>$condition, 'params'=>$params, ), 'pagination'=>array( 'pageSize'=>2, ), )); but ...…
sensorario
  • 20,262
  • 30
  • 97
  • 159
0
votes
1 answer

Invalid argument supplied for foreach() -- When trying to make a query on a SearchModel - Yii2

I was trying to make a search model for a mini Geo location system. Whenever I tried to get the data sorted by directly calling the GeoData model it works unless we try to sort. But when we try to use the CustomMade SearchModel it sends : Invalid…
Yamel Mauge
  • 35
  • 1
  • 5
0
votes
2 answers

yii2 Merge two data provider and show them in a grid

i'm trying to merge two table with different field in a grid but i get an error like i cant call second fist table fields the…
0
votes
1 answer

SQL sorting: order blocks with DESC - but each block is sorted ASC within itself

I have a SQL table with messages and their date of publication. Let's call these messages M1, M2, ... M99. M1 being the newest message. I want to display them (i'm using Yii 1.1 framework) in a whatsapp way: The newest message M1 is on the bottom…
user969914
  • 23
  • 5
0
votes
1 answer

Not being able to get activities for follower's newsfeed in Yii?

I have got two tables Activity ID | user_type | user_id | status 1 | PROFESSIONAL | 15 | Hello 2 | VENDOR | 15 | Hi 3 | PROFESSIONAL | 16 | My status 4 | PROFESSIONAL | 18 | Abcd …
0
votes
2 answers

function in activeDataProvider output returning HTML in yii2

[ 'label' => 'stars', 'value' => function($model){ $stars = $model->score; $result = ""; for($i=1; $i<=$stars;$i++){ $result .= ""; } return $result; }, ], Given the above, I need to…
M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
0
votes
1 answer

How to show records in section with heading from activeDataProvider in yii2

My database structure is as follows id : item : name : price 1 : framework : bootstrap : 90 1 : framework : zend : 100 1 : framework : drupal : 150 1 : responsive : no : 0 1 : responsive : yes : 50 I want to render…
Arif Sami
  • 307
  • 1
  • 2
  • 14
0
votes
1 answer

Yii2: Multiple Model/Controller in Index and Url change

In my Index I need to show the results of two different Tables that are not linked by any relation. I've done that by using two different search models /* @var $searchModel app\modules\book\models\BookNewSearch */ /* @var $searchModelOld…
Arcanis
  • 31
  • 1
  • 5