3

I am quite new to Yii framework and I want to create a form from a couple of models. I have got two tables called users and profiles and the form must be contain both tables columns. Here is the form I have created in my 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 -->

My models are also includes the relation between two tables:

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'),
    );
}

How can I handle my view to connect it to both models at the same time?

1 Answer 1

3

Follow this wiki it will guide you to do what u need

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.