+------------------+
| Invoices |
+------------------+
| id |
| customer_id (Fk) |
| description |
+------------------+
+------------------+
| Customers |
+------------------+
| id |
| firstname |
| lastname |
| description |
+------------------+
數據庫,以便按我的需求量的我做了multimodel。在這多模式的客戶模型在發票model.Now的actionCreate(裝)發票控制器是這樣
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,
));
}
的的actionView()是尋找這樣
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
'customers'=>Invoices::model()->findByAttributes(array('id'=>$_GET['id']))->customer_id,
));
}
現在,當我呈現的形式的RenderPartial和改變了我的代碼在瀏覽文件中像這樣
<?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,
),
),
)); ?>
這表明這樣的錯誤試圖讓行非對象的特性「值」 => $客戶 - > firstname, 那麼有人可以告訴我哪裏錯了嗎?歡迎任何幫助和建議。
改變你的驗證,是這樣的: ' $有效= $模型 - >的validate(); $ valid = $ customers-> validate()&& $ valid; ' – farzan 2012-02-20 05:03:27
雅我已經改變它..它不起作用。 – NewUser 2012-02-20 05:36:44
因此actionView在發票控制器中?這意味着'loadModel($ id)'正在加載發票? – 2012-02-21 13:51:52