Event Attach

Hi!

First of all, I apologize for my bad english

The treatment related event I would like to ask for help from you.

Given a User controller, this have a method called actionAdd and actionMod, actionAdd when called, it is afterSave from I would like to make a certain thing happen , but if the actionMod is called, you also want to make afterSave to make something happen, but not the such that the at actionAdd.

How should this be done?

  1. In the model class, afterSave look at what this model scenario and decide what to do with the basis of?

  2. In the User controller class, in the action with method attachEventHandler attach event handlers?

Do you have any other ideas which can be performed in much the whole thing ?

Unfortunately, I did not get the first two out of me different, but I’m not sure that these are the best solutions.

A larger system is concerned, that is more event handler can be supplied to a controller, only written for the sake of simplicity, the example to illustrate the problem.

Thank you in advance for your help!

if those things are action-specific then put then straight in actions:




public function actionX() {

  ...

  if( $model->save() ) {

    //do the special thing here


    $this->redirect(...);

  }

  ...



if you must use same code in several actions - write a behavior, which binds to onAfterSave event. Do not attach this behavior by default (do not put it in behaviors() in model), but attach it manually in action before calling $model->save().

Thank You for help!