I have the database like this
+------------------+
| Invoices |
+------------------+
| id |
| customer_id (Fk) |
| description |
+------------------+
+------------------+
| Customers |
+------------------+
| id |
| firstname |
| lastname |
| description |
+------------------+
So as per my requirment I made multimodel.In that multimodel Customers model is loaded in Invoices model.Now the actionCreate() of invoice controller is like this
public function actionCreate()
{
$model=new Invoices;
$customers = new Customers;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Invoices'],$_POST['Customers']))
{
$model->attributes = $_POST['Invoices'];
$customers->attributes = $_POST['Customers'];
$valid = $model->validate();
$valid = $customers->validate();
if($valid)
{
$customers->save(false);
$model->customer_id = $customers->getPrimaryKey();
$model->save(false);
$this->redirect(array('view','id'=>$model->id));
}
}
$this->render('create',array(
'model'=>$model,
'customers' => $customers,
));
}
The actionView() is looking like this
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
'customers'=>Invoices::model()->findByAttributes(array('id'=>$_GET['id']))->customer_id,
));
}
Now when I rendered the form with renderpartial and changed my code in View file like this
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
'id',
'customer_id',
array(
'label' => 'Firstname',
'value' => $customers->firstname,
),
array(
'label' => 'Lastname',
'value' => $customers->lastname,
),
array(
'label' => 'description',
'value' => $customers->description,
),
),
)); ?>
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.
i think problem in follow code:
Try this code: