Yii also support developer build modules in web application which is located in /protected/modules folder. Each module have its own model, controller and view like an application. The followings are some tips to generate model and its CRUD for module.
1.Generate a model for module using Gii.
In model generator page, after input Table Name, Model Class name,instead of the Model path application.models value, let's place the alias of models in the module that you want to generate like the following image:As you can see above, we have the alias structure :
application.modules.NAME_OF_MODULE.models
is the model path for all models of module has name : NAME_OF_MODULE .Just change the Name_OF_MODULE to generate in which module you want.
2. Generate CRUD for model in a module
CRUD refer to Create , Read, Update, Delete action,the four basic functions of persistent storage. In Gii,CRUD generator generates a controller and views that implement CRUD operations for the specified data model. So, we can can also generate CRUD for model which locates in module by placing value like the followings:For Model class, just place alias of Model file similar to [1] generate model class.
application.modules.NAME_OF_MODULE.models.MODEL_CLASS_NAME For controller Id, instead of controller class name, input : NAME_OF_MODULE/CONTROLLER_CLASS_NAME to specific controller.