2012-08-26 44 views
1

我的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(); ?> 

的感谢!

+0

当你说“它显示两次”,这是否意味着相同的视图被加载,然后自动刷新? –

+0

其中代码中的内容是重复的,它们是字面上的一个接一个,还是在这两种形式之间还有其他html输出? – Stu

+0

没有。该视图被加载一次,但所有窗体的字段都显示出来,并且在它们的正下方再次显示 – avital

回答

0

我设法呈现前添加以下行来解决它:

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

的感谢!

0

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

+0

你有什么想法?谢谢 – avital