Hello guys, I’m new to PHP and Yii, but I do have programming skills with C#, Java, C++ and C.
I have a question about why we need multiple Controllers? I made a fresh "Hello world" webapp and played for a while. After playing a bit I wonder why we would need multiple Controllers? I mean, if I define all the needed actions (loginAction(), registerAction(), commentAction(), etc…), why would I need a Postcontroller, CommentController…? Or is it to group requests together to keep it organized?
Controllers group some actions to keep them organized, but not only - controllers provides authorization (who can access specific actions), define filters (authFilter, gzip, etc) but also, what is most important, Controller encapsulates common logic between actions. If you have two actions that share some code (like "loadModel" function for "update" and "delete" actions) you put it in private/protected methon in Controller. This way it much more clear that putting everything in one Controller. In very large projects (dozens of actions) putting them all in one file would also impact performace because of PHP compilation process.