How crud create or update action is selected and many buttons on crud form

Hi!

I have 2 questions:

  1. I am trying to understand CRUD demos (like Blog post views and controller) and I don’t understand how Yii determine which action to use - create of update. The only difference is update variable in view form, but nothing else;

  2. I would like to use at least 2 buttons on create or update pages - e.g. like: ‘Save Order’, ‘Save and Place Order’, but both buttons are calling the same action (create or update). How to make that different buttons of the same Yii form calls different actions? I have read another post that one can check $_POS[‘button_name’], but the confusion remains about how Yii choose create of update action.

Hi Thomas ,

Sory but i didn’t understand your first question.But for for your second question i can give you some idea.Since it is just a logical approach. Here is my code for this question




This is my view file where i have created a two button.

<div class="click">

					<div class="main_compoass_login_btn">

						<div class="send_login_btn_left">

							<?php echo CHtml::submitButton('SEND',array("name"=>"button","class"=>"login_btn")); ?>

						</div>

						<div class="send_login_btn_right">

						    <?php echo CHtml::submitButton('SAVE NOW',array("name"=>"button", "class"=>"login_btn")); ?>

						</div>

					</div>

					<div class="lft_lg"></div>

				</div>







And this is my controller file code to handle this approach.


if($_POST['button'] == 'SAVE NOW'){

                        $model->draft_status    =    1;

                        $model->status            =    0;

                        $model->save();

                        Yii :: app()->user->setFlash('message', 'Your Message saved in draft Successfully.');

                     }else{

                         $model->draft_status    =    0;

                        $model->save();

                        Yii :: app()->user->setFlash('message', 'Your Message hase sent Successfully.');

                     } 



I hope after reviewing my code you will get an idea how to do it.