Stop Execution After Render.

Hi all.

How do I stop execution after a render call or is my logic wrong?

This is what I have:




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

{

     if($model->save())

     {

          if(true)

          {

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

          }

     }

}    

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



So what happens is this:

  1. First call to the page a POST of the form is not set, so it will jump to the last render call.

  2. When I submit the form, it will go into the 1st if, then into the second if(model->save) and then into the 3rd if(true) and then call the render inside the 3rd if.

But that is not where it stops, the code will execute further outside all the if’s and render the page again. So now I have the same page content duplicated on a single browser page. It was my understanding that a render will happen and none of the code below it will execute. I was wrong(I think).

So please, how do I prevent it from doing it? Or do I need to put everything in multiple if statements?

Thanks

What is usually done is that after $model->save() – the if(true) block isn’t needed because $model->save either returns true or else stays on the original page showing validation errors – one redirects to (not renders) a different page, usually view.php. Check the blog demo controllers for a guide.

On most other situations if you want to stop execution call Yii::app()->end().