You are viewing revision #4 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version or see the changes made in this revision.
Yii âs CArrayDataProvider is very helpful to display model relation data's directly on it.But it is truely a confusing one because by default it will assume a table field named âidâ as primary key for its pagination purpose and what if you dont have field named âidâ as primary key on your table? so its truely confusing and if you tried to display without an âidâ field on ur table you will get an error like âyourmodel.id is not definedâ.
To solve this CArrayDataProvider confusing problem you just need to use on of its attribute named âkeyFieldâ to specify your primary key field on your table.There is an property named âidâ thats just an id of the dataProvider itself.
i have 2 models ie deal and buyer(MANY_MANY).
so $deal->buyers is the relation i used to display my deal buyers.i used a field named âfacebook_idâ as primary key in model âbuyerâ .see my code.
$dp = new CArrayDataProvider($deal->buyers, array(
'keyField' => 'facebook_id', // PRIMARY KEY
'id' => 'buyers_list' // ID of the data provider itself
));
Regards, sirin k
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.