How to create new Module using gii

Hi,

I would like to create a new module using gii.

The new module is successfully created.

I tried to create new model,Controller,form inside the module

but it always creates these files in not a corresponding module

1196

yii.jpg

Here in this sample,

help to create model,Controller,form inside the email module using gii…?

Let’s say you have a module named admin, and you want to create a new controller that goes into the admin module and it’s name is users.

in this case, when you generate a new controller, in the Controller ID * field, you will pass admin/user so you will have MODULE_NAME/CONTROLLER_NAME instead of having just CONTROLLER_NAME.

Same things for CRUD or models.

To create model inside module[‘email’], you can edit the text-box during creating model. And you need to change the location. By default every models, are created inside models.

For this, in the Model Path you need to edit with : application.modules.email.model

Now your model is created inside email/modules/model/

hi veera,

i have read your post. i think you are not familiar with concepts of yii completely yet. i could suggest a book to go through the concepts of yii and MVC pattern. [quote name=‘Link to yii book’]here is the link to the book’s information: goo.gl/yLX3h
[/quote]
I am interesting to know about you progress with yii framework. all the best. enjoyii.

Hi Veera,

I just ran into the same problem you had when trying to use gii or yiic shell to create a controller for

a module. The above posts give accurate help but missed one step.

You must set your yii web application configuration file to include the module your are building.

I believe this is the problem you are having.

For example, I built a module called "users". Then, I wanted to build a controller for that module.

Before building the controller I first went to the application configuration file:

/webserver_directory/project_name/protected/config/main.php

Then, in that file I found the modules section and added the new module name "users" to it:

‘modules’=>array(

	// uncomment the following to enable the Gii tool


	


	'gii'=>array(


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


		'password'=>'*****',


	 	// If removed, Gii defaults to localhost only. 


		'ipFilters'=>array('127.0.0.1','::1'),


	),


	// Must have or shell command will not put files in module.


            'users'=>array(),


	


), 

Notice, the module section of your config file is also where your gii configuation is.

You need to add the ‘users’=>array(), to the modules=>array. After making this change,

you can use yiic shell or gii to create a controller for the module and it will place

the controller and view files in the module. If you skip this step the controller and view files made

by gii or yiic shell will be placed in the regular controller and view folder instead of the

module’s controller and view folders.

Code to make a module controller in yiic shell.

module users/users login logout listUsers manageUser

I hope this helps.