Controller In Mvc

Hi folks.

I want to ask something :unsure:

When we should make a new controller? On Every new page or a big part in our web

Hi

Creating a controller for every page is too finegrained.

When using Gii, you can see that you can create CRUD operations which will generate one controller for CRUD (Create, Read, Update, Delete).

IMHO a controller is for actions (mostly pages) that you want to keep logically together. Anything related to logging in and logging out would be one controller, but managing users and user passwords would be another (backend related) controller.

So keep pages and actions that belong together in one controller, but keep controllers as small as possible by creating new controllers as soon as the "subject" is sufficiently different.

Further, the controller should not do really do the work - delegate the work as much as possible to methods in the models, extensions, components, … .

OK thanks :lol: I almost make controller for every page haha