50 actions in controller

Dear All,

I have around 50 actions in my controller . Is it OK to keep these many in one control ? Does it impact any performance or any other impacts ?

Thanks for your help … ( sorry for this silly question :) )

Regards

Yii Fan

Yeah, well … I find it a bit much. But if you’re content with it, it’s okay. I cannot imagine any kind of performance regressions ::)

its depend on what are you doing.

generally 50 function in class is nothing

Well, there is no general answer to that as this depends on a few things: If all the actions are logically tied to an entity like a model or a logical entity like “site navigation” then this is perfectly fine (especially if you make heavy use of AJAX this could lead to a lot of actions). I don’t think that this will have any noticeable performance impact. However, check for these points to get an idea if you have too much actions in there or not:

  1. Duplicated code: You have a post controller and a comment controller. The post controller holds actionAddComment() and the commentController holds actionCreate(). Both do essentially the same, so as a comment is always tied to a post you could weed out the create action in your comment controller.

  2. Too much logic: Instead of putting too much logic into your controller try to add it to the models instead. Why? Because you are then able to use the code in every controller without the need to add additional lines. The $model->search() method gii creates is a good example as it returns a dataProvider that a lot of folks would instantiate within a controller action. That’s not necessary.

  3. Separation of concerns: Don’t put too much logic related to model A into the controller of model B as long as A is able to exist without B (post<->comment example above)

Hope it helps

Thank You Da:Sourcerer for confirming

Thank You amiramir for confirming

Thank You Haensel for your excellent explanation , this helps me

Regards

Yii Fan