我对Yii框架还很陌生,我想用几个模型创建一个表单.我有两个称为用户和配置文件的表,并且表单必须同时包含两个表列.这是我在视图中创建的表单:
<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 -->
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'),
);
}
如何处理将视图同时连接到两个模型的视图?
解决方法:
Follow this wiki 它会指导您做您需要做的
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。