Gii nested modules

I had the need to use Gii to create nested modules so I’ve made a few changes in the file " framework / gii / generators / module / moduleCode.php " to attend it to my needs

Using the modifications below you can do this


to create a module “accounts” in forum’s module

You guys should consider to include it into the new version

line 12:

//allows it to accept dot caracters in the module's name

array('moduleID', 'match', 'pattern'=>'/^(\w|\.)+$/', 'message'=>'{attribute} should only contain word characters.'),

I’ve also added a method to get the relative path of the module

//function to get the relative path of the module

	public function getModuleRelativePath(){


    	foreach(explode(".",$this->moduleID) as $module){



    	return $path;


so I’ve modified the methods getModuleClass and getModulePath to this

	public function getModuleClass()


		$dotPos=strpos($this->moduleID,".")>0 ? strrpos($this->moduleID,".")+1 : strpos($this->moduleID,".");

		return ucfirst(substr($this->moduleID,$dotPos)).'Module';


	public function getModulePath()


   	return Yii::app()->basePath.$this->getModuleRelativePath();


The success message neither the tip text isnt changed tho.

or you can replace the file with this one : 969


file to replace:


hope someone find this usefull

Thank you very much!

I really think that this should be added to further releases

thanks dear Gustavo

note that : for using this module we need to add this "child module" in configuration of our "parent module"

here is an example:

my parent module name is : admin.

my child module name is : auth.

1st, i created admin module.

2nd, i created auth module.

3rd, in AdminModule.php , in init() funtion , i added this line:


finally my init function is like this:


public function init() {










Thanks for sharing.

It depends of your use, you only need to do that if you will use the components of the below module

I actually wrote this a loong time ago, I improved it a lot with time, adding a lot of functionalities

I didn’t share it yet because it creates for my applicacion specifically, like the grid it creates is of the class “MPGridView” instead of “CGridView”

Anyway, if you are interested in removing the dependencies I am able to share. It has a controller, a crud, a module, a form and a model generator improved


Easier yet is to extend the below class and call parent::init(); in the child init method

thanks for you shareing

very helpful~~

Hi Gustavo,

I used your guideline to make gii able to generate nested module I it successfully generated. Many thanks for this help. Please have a little more favor, after created a module “Manager” I created a sub module “cms” in manager and tried to create CURD app for a cms table, model generated successfully from model manager in gii, but gii do not generate CURD app files in cms module, it generate all files in manger’s modules views and controller folder.

Could you please tell me the way how I can generate CURD files in nested modules.

Thanks & Regards

Deepak Singh Kushwah

Hi Deepak


Once you know how its easy to create the cruds under the modules e submodules

first of all you must declare all modules and submodules







and then in the controller field of gii crud generator write like this:


and its done

Hi Gustavo,

Thanks for your quick reply. I did exactly you said but still gii tool creating the controller, view files in parent module. Please have a look at the attached png file. manager is the parent module of cms and when I try to create CURD for cms, it create it’s controller and view files in manager’s controller and view folder. Is this the default behavior of gii CURD generator or I am missing.

As I think, if I am making CURD for CMS, it should create all files in CMS sub folders only. Please let me know your kind views on this.


No response???:unsure:


I remember that it was happening, and at first I was copying the files manually

I need to check if I modified gii to fix this bug, but I didn’t have time yet.