gpt4 book ai didi

php - 在 Yii 中从多个模型创建表单

转载 作者:搜寻专家 更新时间:2023-10-31 20:42:38 25 4
gpt4 key购买 nike

我对 Yii 框架很陌生,我想从几个模型中创建一个表单。我有两个名为 users 和 profiles 的表,表单必须包含两个表列。这是我在我的 View 中创建的表单:

<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' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;')); ?></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'),
);
}

如何处理我的 View 以同时将它连接到两个模型?

最佳答案

Follow this wiki 它会指导你做你需要做的事

关于php - 在 Yii 中从多个模型创建表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18776474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com