私は Yii フレームワークを初めて使用し、いくつかのモデルからフォームを作成したいと考えています。ユーザーとプロファイルという 2 つのテーブルがあり、フォームには両方のテーブルの列が含まれている必要があります。私のビューで作成したフォームは次のとおりです。
<div class="form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'users-form',
// 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,
));
?>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<div class="span6 ">
<?php echo $form->labelEx($model, 'firstname'); ?>
<?php echo $form->textField($model, 'firstname', array('size' => 50, 'maxlength' => 50, 'class' => 'input-block-level')); ?>
<?php echo $form->error($model, 'firstname'); ?>
</div>
<div class="span6">
<?php echo $form->labelEx($model, 'lastname'); ?>
<?php echo $form->passwordField($model, 'lastname', array('size' => 50, 'maxlength' => 50, 'class' => 'input-block-level')); ?>
<?php echo $form->error($model, 'lastname'); ?>
</div>
</div>
<div class="row">
<div class="span6 ">
<?php echo $form->labelEx($model, 'username'); ?>
<?php echo $form->textField($model, 'username', array('size' => 30, 'maxlength' => 30, 'class' => 'input-block-level')); ?>
<?php echo $form->error($model, 'username'); ?>
</div>
<div class="span6">
<?php echo $form->labelEx($model, 'password'); ?>
<?php echo $form->passwordField($model, 'password', array('size' => 60, 'maxlength' => 80, 'class' => 'input-block-level')); ?>
<?php echo $form->error($model, 'password'); ?>
</div>
</div>
<div class="row">
<div class="span6">
<?php echo $form->labelEx($model, 'email'); ?>
<?php echo $form->textField($model, 'email', array('size' => 60, 'maxlength' => 100, 'class' => 'input-block-level')); ?>
<?php echo $form->error($model, 'email'); ?>
</div>
<div class="span6">
<?php echo $form->labelEx($model, 'deactive'); ?>
<?php $accountStatus = array(0 => 'فعال', 1 => 'غیر فعال'); ?>
<div class="radio-block"><?php echo $form->radioButtonList($model, 'deactive', $accountStatus, array('separator' => ' ')); ?></div>
<?php echo $form->error($model, 'deactive'); ?>
</div>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'ایجاد کاربر' : 'Save', array('class' => 'btn btn-info pull-left')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
私のモデルには、2 つのテーブル間の関係も含まれています。
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array('profiles' => array(self::HAS_ONE, 'Profiles', 'userid'),
)
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'user' => array(self::BELONGS_TO, 'Users', 'userid'),
);
}
ビューを両方のモデルに同時に接続するにはどうすればよいですか?