Sub Modules

Hello.

I’m a Yii newbie and I’m trying to work with modules and submodules. However, there is so little documentation on them and its a pain, really.

I’d appreciate if anyone can point me towards resources on them.

Also, how does one declare a submodule for an existing module?

Secondly, how do I create controllers in a submodule using Gii?

Thanks in advance

Hi Odun

Welcome to the world of Yii :)

The Yii tutorial answers most of your questions on modules and sub modules. The comments that appear below the tutorial are really helpful as well. The Module documentation is always a good point of reference as you go along.

To declare a sub module, in your config.php, you would have something like so:




return array(

    ......

    'modules'=>array(


        'modulename'=>array(


                'modules'=>array( 

                              'submodulename',

                            ),

                           ),

           ),

 ....

);



Once the sub module has been declared, in the Gii controller generator, give the controllerid as <modulename>/<submodulename>/<controllername>

Hope that helps.

A simple tutorial:

In this example, you want to create a module core with a submodule management in the website.

Create with gii the two modules. Add the folder "modules" in the module core . Remove the module management in this new folder.

The File-Structure should be a kind of this:




 /protected

 ---/modules

    ---/core

       ---/controllers

       ---/modules

          ---/management

       --- ...

       ---/views



Now, You must configure your main.php or config.php in the folder "config" ( in the root-folder "protected"):




	'modules'=>array(

		// uncomment the following to enable the Gii tool

        'gii' => array(

            'class' => 'system.gii.GiiModule',

            'generatorPaths' => array(

                'bootstrap.gii', // since 0.9.1 /Twitter bootstrap)

            ),

			),

        'core'=>array(

        		'modules'=>array(

        				'management',

        		                ),

                      ),

        ),



And modify the "import"-Array in this file:




		// [MODULE] Core

		'application.modules.core.models.*',

		'application.modules.core.components.*',

		'application.modules.core.widgets.*',

		

		// [MODULE] Management

		'application.modules.core.modules.management.models.*',

		'application.modules.core.modules.management.components.*',	



Now, you have the possibility to use all components, models, etc. of the submodule "management" in the same kind like the module core.

For example, if you want to add a submodule login in submodule management, you have to modify your "modules"-Array like that:




        'core'=>array(

        		'modules'=>array(

        				'management' => array(

                                                         'modules' => array(

                                                                       'login',

                                                                      ),

                                                        ),

        		                ),

                      ),

        ),



You have to modify your "import"-Array too.

And so on, and so on.

I hope, that can help you.

Best Regards,

Riff