Note that there are some explanatory texts on larger screens.

plurals
  1. POError in getting second models value in Yii multimodel form
    text
    copied!<p>I have the database like this</p> <pre><code>+------------------+ | Invoices | +------------------+ | id | | customer_id (Fk) | | description | +------------------+ +------------------+ | Customers | +------------------+ | id | | firstname | | lastname | | description | +------------------+ </code></pre> <p>So as per my requirment I made <a href="http://www.yiiframework.com/wiki/19/how-to-use-a-single-form-to-collect-data-for-two-or-more-models/" rel="nofollow">multimodel</a>.In that multimodel Customers model is loaded in Invoices model.Now the actionCreate() of invoice controller is like this</p> <pre><code>public function actionCreate() { $model=new Invoices; $customers = new Customers; // Uncomment the following line if AJAX validation is needed // $this-&gt;performAjaxValidation($model); if (isset($_POST['Invoices'],$_POST['Customers'])) { $model-&gt;attributes = $_POST['Invoices']; $customers-&gt;attributes = $_POST['Customers']; $valid = $model-&gt;validate(); $valid = $customers-&gt;validate(); if($valid) { $customers-&gt;save(false); $model-&gt;customer_id = $customers-&gt;getPrimaryKey(); $model-&gt;save(false); $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id)); } } $this-&gt;render('create',array( 'model'=&gt;$model, 'customers' =&gt; $customers, )); } </code></pre> <p>The actionView() is looking like this</p> <pre><code> public function actionView($id) { $this-&gt;render('view',array( 'model'=&gt;$this-&gt;loadModel($id), 'customers'=&gt;Invoices::model()-&gt;findByAttributes(array('id'=&gt;$_GET['id']))-&gt;customer_id, )); } </code></pre> <p>Now when I rendered the form with renderpartial and changed my code in View file like this</p> <pre><code> &lt;?php $this-&gt;widget('zii.widgets.CDetailView', array( 'data'=&gt;$model, 'attributes'=&gt;array( 'id', 'customer_id', array( 'label' =&gt; 'Firstname', 'value' =&gt; $customers-&gt;firstname, ), array( 'label' =&gt; 'Lastname', 'value' =&gt; $customers-&gt;lastname, ), array( 'label' =&gt; 'description', 'value' =&gt; $customers-&gt;description, ), ), )); ?&gt; </code></pre> <p>It showed an error like this Trying to get property of non-object in line 'value' => $customers->firstname, So can someone tell me where the wrong part?Any help and suggestions are welcome.</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