Note that there are some explanatory texts on larger screens.

plurals
  1. POpassing an array from an user defined action in controller to a view in Yii
    text
    copied!<p>In my Yii application I need to perform joint queries in controller and display the final view in views. this is the mysql query I need to perform.I hav three tables namely,items,manufacturers,items_manufacturers</p> <pre><code>SELECT items.id,item_desc,manufacturers.id,manufacturers.name FROM items_manufacturers,items,manufacturers WHERE items_manufacturers.item_id=item.id AND items_manufacturers.manufacturer_id=manufacturers.id. </code></pre> <p>The relation between the models is</p> <pre><code>public function relations() { 'item' =&gt; array(self::BELONGS_TO, 'Items', 'item_id'), 'manufacturer' =&gt; array(self::BELONGS_TO, 'Manufacturers', 'manufacturer_id'), 'itemsManufacturersLocations' =&gt; array(self::HAS_MANY, 'ItemsManufacturersLocations', 'items_manufacturer_id'), ); </code></pre> <p>This is the Query I performed in the controller</p> <pre><code>public function actionJoint() { $imf=ItemsManufacturers::model()-&gt;with('item','manufacturer')-&gt;findAll(); $this-&gt;render('joint',array( 'imf'=&gt;$imf )); } </code></pre> <p>This is the code I implemented in the view</p> <pre><code>&lt;?php $this-&gt;breadcrumbs=array( 'joint', ); $this-&gt;menu=array( array('label'=&gt;'Create ItemsManufacturers', 'url'=&gt;array('create')), array('label'=&gt;'Manage ItemsManufacturers', 'url'=&gt;array('admin')), ); ?&gt; &lt;h1&gt; List Items and Manufacturers &lt;/h1&gt; &lt;?php $this-&gt;widget('zii.widgets.CListView',array( 'dataProvider'=&gt;$imf, 'itemView'=&gt;'_jointview', )); ?&gt; </code></pre> <p>My code for the render of partial of view </p> <pre><code> &lt;?php /* @var $this ItemsManufacturersController */ /* @var $data ItemsManufacturers */ ?&gt; &lt;div class="view"&gt; &lt;b&gt;&lt;?php echo CHtml::encode($data-&gt;getAttributeLabel('item_desc')); ?&gt;:&lt;/b&gt; &lt;?php echo CHtml::encode($data-&gt;item_desc); ?&gt; &lt;br /&gt; &lt;b&gt;&lt;?php echo CHtml::encode($data-&gt;getAttributeLabel('name')); ?&gt;:&lt;/b&gt; &lt;?php echo CHtml::encode($data-&gt;name); ?&gt; &lt;br /&gt; &lt;/div&gt; </code></pre> <p>But I am getting this error which I am unable to rectify.. Anybody help me with this.</p> <pre><code>Fatal error: Call to a member function getData() on a non-object in /var/www/yii_framework/framework/zii/widgets/CBaseListView.php on line 107 </code></pre> <p>Any body help me how should I proceed since I am a newbie</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload