Cannot modify header information

HI, Guys

I follow the actionContact of SiteController to do the a actionRegister of UserController

I modify ContactForm.php to generate a RegisterForm.php

I had no idea why it will generate "Cannot modify header information "

when do the "$this->refresh();"

I used headers_sent to check where the header is sent.

I found headers will be sent when "$register = new RegisterForm();"

no matter post action or not …

any doc i miss ?

could anybody do me a favor ?

thx~

This is my code

UserController




  /**

   * register user

   */

  public function actionRegister()

  {

    $register = new RegisterForm();

    /*

    if ( headers_sent() ) {

      print 'sent';exit;

    }

    */

    if(isset($_POST['RegisterForm']))

    {

      $register->attributes=$_POST['RegisterForm'];

      if($register->validate())

      {

        Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');

        $this->refresh();

      }

    }

    $this->render('register',array('register'=>$register));

  }



RegisterForm




<?php


/**

 * RegisterForm class.

 * RegisterForm is the data structure for keeping

 * contact form data. It is used by the 'contact' action of 'SiteController'.

 */

class RegisterForm extends CFormModel

{

  public $account;

  public $password;

  public $name;

  public $gender;

  public $email;

  public $company_name;

  public $country;

  public $fax;

  public $mobile;

  public $postcode_id;

  public $verifyCode;


  /**

   * Declares the validation rules.

   */

  public function rules()

  {

    return array(

      // name, email are required

      array('account, password, name, gender, email', 'required'),

      // email has to be a valid email address

      array('email', 'email'),

      // verifyCode needs to be entered correctly

      array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),

    );

  }


  /**

   * Declares customized attribute labels.

   * If not declared here, an attribute would have a label that is

   * the same as its name with the first letter in upper case.

   */

  public function attributeLabels()

  {

    return array(

      'verifyCode'=>'Verification Code',

    );

  }

}



Look there


/* RegisterForm */ 

<?php  /**  

* RegisterForm class.  

* RegisterForm is the data structure for keeping  

* contact form data. It is used by the 'contact' action of 'SiteController'.  

*/ 

class RegisterForm extends CFormModel {

there should be nothing before the <?php opening tag

Thx ^^.

my question is not caused by this, it’s my posting miss.

I just copy the some code to a new file

It just works…

i guess that the error is caused by bom…

yes it could be bom, make sure to select the correct file format ;)