我收到一个错误
致命错误:在第 1414 行的 C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php 中的非对象上调用成员函数 isAttributeRequired()。
我有两张表格派对和客户,我想以一种形式编辑派对视图,其中包含客户字段
在我的控制器中
public function actionUpdate($id)
{
//$party_form = new Party;
//$customer_form = new Customer;
$model=$this->loadModel($id);
$customer_form=$this->loadCusModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Party'], $_POST['Customer']))
{
$model->attributes=$_POST['Party'];
$customer_form->attributes=$_POST['Customer'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('update',array(
'model'=>$model,
'customer_form'=>$customer_form,
));
}
........
public function loadModel($id)
{
$model=Party::model()->with()->findByPk((int)$id);
//$model=Party::model()->with(array('customer'=> array('select'=>'first_name, mobile, phone, type')))->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
public function loadCusModel($id)
{
$customer_form=Customer::model()->with()->findByPk($id);
/*
$cmd = Yii::app()->db->createCommand();
$cmd->select = 'party.account_title';
$cmd->from = 'customer, party';
$cmd->where = 'customer.id=party.customer_id';
$cmd->andWhere("party.id=$id");
$row = $cmd->queryRow();
$customer_form=$row;
if($customer_form===null)
throw new CHttpException(404,'The requested page does not exist.');
return $party_form;
*/
if($customer_form===null) {
throw new CHttpException(404,'The requested page does not exist.');
return $customer_form;
}
}
在更新.php
<?php
/* @var $this PartyController */
/* @var $model Party */
$this->breadcrumbs=array(
'Parties'=>array('index'),
$model->id=>array('view','id'=>$model->id),
'Update',
);
$this->menu=array(
array('label'=>'List Party', 'url'=>array('index')),
array('label'=>'Create Party', 'url'=>array('create')),
array('label'=>'View Party', 'url'=>array('view', 'id'=>$model->id)),
array('label'=>'Manage Party', 'url'=>array('admin')),
);
?>
<h1>Update Party <?php echo $model->id; ?></h1>
<?php $this->renderPartial('_formUpd', array('model'=>$model, 'customer_form'=>$customer_form)); ?>
和_formUpd.php
<?php
/* @var $this PartyController */
/* @var $model Party */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'party-formUpd',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
'htmlOptions' => array(
'autocomplete' => 'off',
)
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<?php //echo $form->errorSummary($customer_form); ?>
<div class="row">
<?php echo $form->labelEx($customer_form,'first_name'); ?>
<?php echo $form->textField($customer_form,'first_name',array('size'=>30,'maxlength'=>30, 'style' => 'text-transform:uppercase')); ?>
<?php echo $form->error($customer_form,'first_name'); ?>
</div>
<div class="row">
<?php //echo $form->labelEx($model,'last_name'); ?>
<?php //echo $form->textField($model,'last_name',array('size'=>30,'maxlength'=>30, 'style' => 'text-transform:uppercase')); ?>
<?php //echo $form->error($model,'last_name'); ?>
</div>
............
<div class="row buttons">
<?php //echo CHtml::submitButton($party_form->isNewRecord ? 'Create' : 'Save'); ?>
<?php
$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Submit', 'size'=>'large'));
?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
请帮忙..