Access var for entire module

I have the following structure:





Is this a correct way of structuring groups? or is better





And another question. I need group object in all actions controllers under group module and i dont want to write the following code in all controllers

$group = Group::model()->findByPk($_GET['idgroup']);

The url’s like:



What is the right way to do this?

Answer to first question is that both of them are correct. You must decide yourself, which solution to use, depending on what you want to achieve?

In first example forum, gallery and events are submodules of module called group and that is why they should be in structure, like in your example. I’m using the very same structure to have administration components being as submodules of main admin module, which works as a gathering elements and does nothing else than to generate list of links leading to each of submodule. This way I can reuse this structure in my every application, but install only this administration modules, which are required by current project. But you have to remember that each module (including main or top module - group in your example) must be fully functional module, therefore aside structure, you showed, it has to contain all necessary elements like at least one, default controller and view for it - even if in your project they do nothing special.

Second example is, on the other hand, valid structure for situation, when you have only one module called group, therefore you put it directly inside modules subfolder and add necessary controllers to it.

To summarize: It depends, what you want to achieve. If both forum, gallery and evens are simple elements of your page, than putting them into separate modules (submodules of group module) is in my opinion just a waste of time and I would suggest second solution. But even looking at names (forum) it seems that you’re ratehr building something bigger (forum itself contains many controllers and views) and therefore first approach would be much better. It requires a bit more coding (submodules often have the same or similar controllers and views), but it helps in a better project organisation and you can reuse these submodules in different projects. As they are in fact separate applications (look for module definition in Yii documentation) and can co-exist alone in different projects.