エラーが発生する
致命的なエラー: C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php の 1414 行目の非オブジェクトでメンバー関数 isAttributeRequired() を呼び出します。
パーティーと顧客の 2 つのテーブルがあり、顧客フィールドを含む 1 つのフォームでパーティー ビューを編集したい
私のコントローラーで
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;
}
}
update.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 -->
助けてください..