Reuse Controller Actions

Suppose I have protected/controllers/PostController/actionCreate()

How can I re-use this same action (and its view) in protected/modules/admin/controllers/PostController/actionCreate()

I do not want to redirect the user - I just don’t want to have to replicate the same code in both actions.

Create a CAction class?




class PostCreate extends CAction

{

  public function run()

  {


  }

}



Then reference it in your controller.




public function actions()

{

  return array(

    'create' => 'path here to action class file'

  );

}



You could just forward the request: http://www.yiiframework.com/doc/api/1.1/CController#forward-detail

Keith - using forward() also brings in the layout file, which I do not want.

alex-w - do I need to create separate class files for each action?

Anybody got any ideas?

No, You can still have actions in the controller.

Creating an action class just allows you to use it from other controllers.