Change the default location of file

I am going to create a new module, ‘message’ [protected/modules/message/]. This module is used for internal mail system.

The problem here is: I created module. Required files and folders are created using Gii tool. Now when I create a new module "Messagemaster.php" it is created inside protected/models/

So how can I generate required files using Gii inside protected/modules/message/ or required destination?

Are you sure? If I’m not mistaken it is impossible for Gii to generate a module inside models folder! Gii is generating modules in modules folder and models in models folder, both being a subfolder of protected folder.

I don’t quite understand what do you mean by reguired files and folders? CRUD files? Model? Controller?

But no matter, what you want to achieve the simpliest way to do it, is to prefix your element (model, controller) name with module name and / sign. If you click in a field titled Controller ID in gii, a popup-help will show up saying:

Which means that you should message/Messagemaster, if you want to generate MessagemasterController.php inside message module.

Just to high light my problem once:

I made a module name ‘message’ using Gii, which is the subfolder of protected folder. Inside messasge module, it has following subfolder generated by Gii : components, controllers, messages, models & views.

Now what I want is: the models [models files] created using Gii should reside inside ‘models’ folder. It’s location is: modules/models/. Ironically it automatically resided inside the protected/model which is not my desire location of the file.

Now, I hope you are clear.

Model Generator of Gii Tool does not allow to generate models somewhere else than in main application. But what seems to be the problem? Just generate model file (always one PHP file) in main application folder (that is protected/models) and then simply move it to your modules/message/models folder? There isn’t even any problem if you already have some model named the same in main application. You generate Model using Gii with different name and then only rename the file and class definition after moving file to modules subfolder.

But the general question is, why you want to do this? Model Generator does not allow generating models in modules because it isn’t necessary to do so. All models should be kept in main application model files, as from there they are accessible by both main application and modules. If you move your model definition to a subfolder, then this model will not be accessible by main application (unless you add additional line to main application configuration file to include it).

Thank you, Trejder for the reply. I was just wondering whether we can create those files in different location or not. Manually I had done in the same way what you have suggested.

My Opinion: If every thing is created inside the default location of model, controller,… then what is the use of models, controller, views,. inside modules?? I am in confuse here.

To make a better understanding of how it works, try to see module as application-inside-application. You have views and controllers for controlling your main application and you have a separate copy of them to control module itself. Models can be shared in main application models folder, but they can also be put separately to both main application and module’s models folder - it is up to you, what you want to achieve.

Thanks once again for your suggestion.

Always my pleasure! :]

Just click on the default Model Path field and enter the location of your choice

thus, in your case




application.modules.message.models



/Tommy

I tried but the default location couldn’t change. I could not find the editable option in Gii.

Thanks I got the solution.

After creating module(eg. message) we need to add a few code in protected/config/main.php




	'modules'=>array(

		// uncomment the following to enable the Gii tool

		

		'gii'=>array(

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

			'password'=>'123',

		),

	   [b] 'message',   [/b] 	

	),



Then using Model Generator in Gii, when creating different models we can change the default Model Path, ‘application.modles’ to our required path (eg.: ‘application.modles’ or ‘application.xxxx’) .

Now this will create a module inside Module/message/models/

Thanks all for your great suggestion.

[b]

[/b]

When in Gii --> Model Generator, you have to find field named "Model Path". It is editable… after you click it! :]

Thanks Trejden.

At first I was unaware that every field in the Gii are editable. This was the problem. Now I get the answer when I mistakly clicked on the text box it was edited,