Doubt about save

Good afternoon

I have a form it is working ok, but in this form I have a field "qtd_clientes", this field is numerical, if i click on "create" the information are saved, but I need if the field "qtd_clientes" is greater than 1, fo exemplo the value of "qtd_clientes" is 3, must save the information 3 times on my database. How can I Do this?

You can create a filter where you check that value before the action and proceed according to it.

Thank you for the help

I seen the example but I understand the idea. I should create function beforeAction, and this function call de actionCreate, until save the amount typed in field "qtd_clientes"? How can I Do this?

Hi Alexandre,

        You can use the afterSave function. I give an example

protected function afterSave()


     if(parent::afterSave()) {

        // write down your own code.



Hope it can be helful to you.

Thank you

I managed to make the example, see:

public function actionCreate()


for($i=1 ; $i<=2 ; $i++)


                    $model=new Cliente;


                    // Uncomment the following line if AJAX validation is needed

                    // $this->performAjaxValidation($model);






                        if($i == 2){$this->redirect(array('index'));}







This code save the information 2 times on data base, but I put the value that finished loop direct on code $i<=2, I need get this value that be in "qtd_clientes" field of my _form.php. But I call the $model=new Cliente; inside the loop and I can not get the value before start loop. Whats I need change to do this?

perhaps you can use tabular input http://www.yiiframew…1/en/form.table

also put $model->save(); outside the loop to prevent heavy db workload

Good night

I dont need tabular input, becouse I don’t want repeat The fields on the form, I need save the same information multiple times. The user typed the information on the form and the system save this information multiple times in database. For example if user typed value 3 in the field qtd_clientes, the system save the same infomation 3 times, if the user typed 4, the system save 4 times in the database.

You will have to set $model->isNewRecord to false or the same record will be updated on repeated save() calls.

Also read e.g. this thread (or search the forum for similar topics).


guys this my example

    public function afterSave()







but,this not working. how can i do?