I'm reading the book and wanna understand the actionCreate of UserController.
Here is the code:
public function actionCreate()
{
$model=new User;
if(isset($_POST['User']))
{
$model->attributes=$_POST['User'];
if($model->save())
$this->redirect(array('view','id'=>$model->user_id));
}
$this->render('create',array(
'model'=>$model,
));
}I've debugged the code (I set the breakpoint at this line)
$model=new User;and see the fact that:
First the isset($_POST['User']) has value of false and then
$this->render('create',array(
'model'=>$model
)); is executed.I filled the data to the form and then the control back to the line $model=new User; Now isset($_POST['User']) has value of true, so the code
$model->attributes=$_POST['User'];
if($model->save())
$this->redirect(array('view','id'=>$model->user_id)); executed.Well this is fairly weird because the line $model=new User; seems to be executed twice.
Is any thing wrong with my debugging or thinking?
Any suggestion would be appreciated!
Cheers!

Help











