Teach Yii To Recognise Path To Controller Correctly

I’m struggling with the following issue:

There is the following file structure:




protected/

  controllers/

    SoftwareController.php

    software/

      AbcController.php



The SoftwareController.php controller handles the index action, eg: example.com/software/index.

The problem is that actions supposed to be served by AbcController are caught by SoftwareController. When I specify the URL as example.com/software/abc/index, the SoftwareController engages and tries to handle the abc action (and fails of course).

The question is: how do I make Yii figure out that software/index is to be served by SoftwareController, and software/abc/* by software/AbcController?

Just move your AbcController.php file to your controllers/ folder and call it example.com/abc/index

Thanks bettor, but this is not the solution I’m looking for. I want to keep my URL clean and structured the same way the site content is organised, otherwise you’ll end up with hundreds of controllers in the controllers/ folder.

Ah please forgive my negligence. so software/ folder is a subfolder of controllers/ right? Ok I first thought that they are at the same level. In your case I suspect that the problem is that your subfolder has the same name as an actual controller file. So a good solution would be to name your subfolder uniquely!

That’s also not an option. The idea is that there’s the software/index action, which is shortened to software/, and further product pages software/abc, software/def etc. (those are handled each by a dedicated controller).

Maybe the idea is bad?

Are you also going to do the same with models and views?

Perhaps you should think about modules instead?

Models not, they are used across the site and thus don’t require a hierarchical organisation.

Views yes, that’s also how Yii handles them by default, isn’t it? For instance, controller controllers/abc/DefController looks for views in views/abc/def.

I want the structure of the website to follow the organisation of information. Which is hierarchical, and this is standard on many websites. So when you open example.com/software/ you get a Software title page, and example.com/software/productA shows you info about Product A.

What is bad about this idea?