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

Join tables in Yii

I have a query like this: SELECT jo . * , pc.checklist_id FROM job_order_candidates jo, pdpa_checklist pc WHERE jo.job_id = '5755' AND jo.shortlisted = '1' AND pc.job_id = '5755' I need to write it in Yii format, how to do it? At the…
CnV
  • 381
  • 4
  • 20
0
votes
1 answer

Join 2 tables using CActiveDataProvider

I've had some problems joining two tables with CActiveDataProvider The tables are: question(id,description) , questionInFeedback(feedbackId,questionId) and the relations : feedback=> 'questionInFeedbacks' =>…
Arik
  • 55
  • 7
0
votes
1 answer

CdbCriteria BELONG_TO

I have a model (Inmueble) with this relation: 'direccion' => array(self::BELONGS_TO, 'Direccion', 'direccion_id_direccion'), In this example: $criteria=new CDbCriteria; $criteria->addCondition('name = ' .$name,'AND'); $listInmueble=new…
jvrdom
  • 358
  • 1
  • 8
  • 18
0
votes
1 answer

Yii. CGridView in frontend. CActiveDataProvider without $model->search()

I don't know if it is possible, but suppose it must be. I need to present some data in frontend view - the list of companies in tabular form: Company name 1 - Country 1 - Website 1 - etc... Company name 2 - Country 2 - Website 2 - etc... etc... I'm…
Decd
  • 65
  • 8
0
votes
1 answer

How in yii make subquery for calculaion number of rows in related table in 1 request?

How in yii 1.1.7 using CDbCriteria and CActiveDataProvider to make subquery for calculaion number of rows in related table in 1 request ? In CodeIgniter I wrote like : $CategoryFactory = ORM::factory('category'); $CategoryFactory->select( DB::expr(…
user2339232
  • 757
  • 3
  • 11
  • 22
0
votes
2 answers

yii query with 4 table on CActiveDataProvider

hi master i've 4 tables -pegawai -penilaian -universitas -jurusan I usually use SELECT u.nama_univ, j.singkatan, peg.* FROM pegawai AS peg LEFT JOIN penilaian AS pen ON pen.no_test=peg.no_test LEFT JOIN universitas AS u ON…
0
votes
0 answers

Get cache with CActiveDataProvider

I was able to store the auery using "CActiveDataProvider" in cache, but it seem like it's not get from the cache, what i am doing wrong? My config is: 'cache'=>array( 'class'=>'CFileCache', ), Controller: $dependecy = new…
0
votes
2 answers

Paginate Gridview by Month in Yii

Is it possible to paginate a gridview by month? I'm guessing I can achieve this via ActiveDataProvider by adding a criteria and creating navigations to generate the results per month. But is there an easy way or something built-in in Yii already?
JohnnyQ
  • 4,839
  • 6
  • 47
  • 65
0
votes
1 answer

CGridView for custom CActiveDataProvider select

So the problem is, that I have a view that will render a CGridView containing a count value. I had to make a custom CDbCriteria so that I could select the right infos. Now I can't display it in a CGridView. Here is my controller action that builds…
0x9BD0
  • 1,542
  • 18
  • 41
0
votes
1 answer

Sorting ActiveDataprovider by virtual attribute

Homeowners post jobs. Jobs are carried out by Tradesman. Homeowners review the way a job was carried out (essentially they rate a Tradesman) by a review. Homeowners and Tradesman are both instances of model User differentiated by a role id, Besides…
veelen
  • 1,916
  • 19
  • 26
0
votes
2 answers

Yii criteria params array whit strstr function

I have this criteria params array (i try this, but it's not working): $dataProvider = new CActiveDataProvider('mydata', array( 'criteria'=>array( 'condition' => 'row=:id', 'params' => array(**strstr(':id', '.')**…
Swissa Yaakov
  • 186
  • 3
  • 15
0
votes
1 answer

Yii CActiveDataProvider different _item view based on item attributes

I'm using CActiveDataProvider to populate a webpage showing messages between users. I have a view php file that uses 'zii.widgets.CListView' in conjunction with the CActiveDataProvider. I'm using a partial _item.php file to render each individual…
James
  • 118
  • 1
  • 10
0
votes
1 answer

Property CActiveDataProvider.Select Not Defined in YII

i am having a Model called Activity, in that have the search() defined as below. but i cant think why when i call it this way this error prompts up.. Internal Server Error Property "CActiveDataProvider.select" is not defined. Calling way.. //Get…
dev1234
  • 5,376
  • 15
  • 56
  • 115
0
votes
1 answer

yii active record NOT IN query

How can we implement CActive Record for this query in yii SELECT * FROM location WHERE locationid NOT IN ( SELECT location FROM memberlocation WHERE memberid = 2371)
0
votes
1 answer

Yii Sortable Column in CGridView

I have a calculated column I wanna have sortable. I have a get method for it... public function getCur_margin() { return number_format(($this->store_cost / $this->store_price) / $this->store_cost * 100, 2) . '%'; } And I followed this…
casraf
  • 21,085
  • 9
  • 56
  • 91