Hmmm, I don’t recognize “MDataProvider”, but assume it’s like the other ones.
Calling the return of your dataprovider “$vendors” is probably a little confusing; I’d instead call it $vendorDataProvider, and you can’t use it to access individual attributes of an individual member, such as $vendors->actions.
What are you trying to accomplish with the if ($vendors->actions) test?
MDataProvider is extending CActiveDataProvider according to another topic here on the forum, to make joins better i think.
I need to list out the actions for each vendor (entered by user) like i would be able to in Vendors::model()->with(‘actions’)->findAll() or whatever, is there a way to do that with the dataprovider?
Thanks steve, Its the second one i’m trying to achieve. I created a minimal dashboard to show new vendors along with actions that other users have taken (emails, phonecall etc.)
Ok, this will be straightforward - I’ll leave it as a skeleton showing how it works, you can expand it as you need to. There are three parts:
// in your controller
public function actionVendorActions()
{
$this->render('vendoractions', array(
'dataProvider' => new MActiveDataProvider('Vendor')
) );
}
// in your view protected/views/SOMETHING/vendoractions.php
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view'
) );
// in the partial view: protected/views/SOMETHING/_view.php
<div class="view">
<?php
// here you do whatever you like to show the vendor and actions
echo "Vendor name: " . CHtml::encode($data->name} . "\n";
echo "Vendor phone: " . CHtml::encode($data->phone) . "\n";
if ( count($data->actions) == 0 )
{
echo " No actions for his vendor\n";
}
else
{
echo CHtml::openTag('ul', array() );
foreach ($data->actions as $action)
{
// add what you need here
echo CHtml::tag('li', array(), "Action: " . CHtml::encode($action->name) );
}
echo CHtml::closeTag('ul');
}
?>
</div>
The main point is that in your Item View (the last one), you can do whatever you like, and assuming you set up a $vendor->actions relation in the Vendor model, this should work just fine.
Note: I haven’t tried any of this, so I might be missing a comma or a parenthesis or something. I hope it helps convey the idea.