Yii表单字段呈现两次

时间:2012-08-26 12:15:50

标签: php yii

我在注册页面中的yii表单的字段会呈现两次!! 任何人都可以帮我找出导致这种情况的原因吗?

这是来自控制器的代码:

public function actionRegister()
{
    $form=new Users;

            // collect user input data
            if(isset($_POST['Users']))
            {
                    $form->attributes=$_POST['Users']; // set all attributes with post
                    // NOTE Changes to any $form->value have to be performed BEFORE $form-validate()
                    // or else it won't save to the database. 

                    // validate user input and redirect to previous page if valid
                    if($form->validate())
                    {
                            // save user registration
                            $form->save();
                            $this->redirect(Yii::app()->createUrl('site/login'));
                    }
            }
            // display the registration form
            $this->render('register',array('form'=>$form));  
}

这是视图中的代码:

<?php $pagetitle = "Hubylon | Register"; ?>
<?php $this->breadcrumbs=array('Register'); ?>


<div class="yiiForm">
<?php echo CHtml::beginForm(); ?>

<?php echo CHtml::errorSummary($form); ?>

<div class="row">
    <table>
        <tr>
            <td>*<?php echo CHtml::activeLabel($form,'username'); ?>:</td>
            <td><?php echo CHtml::activeTextField($form,'username'); ?></td>
            <td><?php echo CHtml::error($form,'username',array('style' => 'color:red;font-size:11px;')); ?></td>
        </tr>
    </table>
</div>

<div class="row">
    <table>
        <tr>
            <td>*<?php echo CHtml::activeLabel($form,'password'); ?>:</td>
            <td><?php echo CHtml::activePasswordField($form,'password'); ?></td>
            <td><?php echo CHtml::error($form,'password',array('style' => 'color:red;font-size:11px;')); ?></td>
        </tr>
    </table>
</div>

<div class="row">
    <table>
        <tr>
            <td>*<?php echo CHtml::activeLabel($form,'confirmPassword'); ?>:</td>
            <td><?php echo CHtml::activePasswordField($form,'confirmPassword'); ?></td>
            <td><?php echo CHtml::error($form,'confirmPassword',array('style' => 'color:red;font-size:11px;')); ?></td>
        </tr>
    </table>
</div>

<div class="row">
    <table>
        <tr>
            <td><?php echo CHtml::activeLabel($form,'first_name'); ?>:</td>
            <td><?php echo CHtml::activeTextField($form,'first_name'); ?></td>
            <td><?php echo CHtml::error($form,'first_name',array('style' => 'color:red;font-size:11px;')); ?></td>
        </tr>
    </table>
</div>
<div class="row">
    <table>
        <tr>
            <td><?php echo CHtml::activeLabel($form,'birthdate'); ?>:</td>
            <td><?php 
                $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'attribute'=>'birthdate',
                    'model' => $form,
                    //'language'=>Yii::app()->language=='en' ? 'en' : null,
                    'options'=>array(
                        'dateFormat'=>'yy-mm-dd',
                        'defaultDate'=>$form->birthdate,
                        'buttonImage'=>Yii::app()->baseUrl.'/images/icons.date.png',
                        'buttomImageOnly'=>true,
                        'showAnim'=>'fold',
                        'showOn'=>'button',
                        'yearRange'=>'1900',),
                    'htmlOptions'=>array(
                        'style'=>'width:80px;vertical-align:top'
                    ),
                ));
           ?></td>
        </tr>
    </table>
</div>

<div class="action">
<?php echo CHtml::submitButton('Register'); ?>
</div>

<?php echo CHtml::endForm(); ?>

谢谢!

2 个答案:

答案 0 :(得分:0)

似乎你提供的代码没有问题,
但也许你可以检查布局和当前控制器的init()方法。

答案 1 :(得分:0)

我设法通过在渲染之前添加以下行来解决它:

$this->layout = '//layouts/login'; 

谢谢!