How to generate crud, models or forms in Modules ?
This is simple but tricky for novice. If you have good understanding of path in YII (or in any computer language) then you can easily understand it.
Okey , let's start :
These are keywords which are use in Yii framework :
system: Refers to the Yii framework directory.zii: Refers to the Zii library directory.application: Refers to the application's base directory. Using this you can point your base directory. You can say this will be root directory of all directories of your project.webroot: Refers to the directory containing the entry script file.ext: Refers to the directory containing all third-party extensions.
Example: Suppose you have to access models of modules 'Group'. Let say directory structure is :
/opt/lampp/htdocs/TestProject/modules/model/testmodle.php
and you want to get reference of "testmodel.php" file in your program. One solution is you just give the full path of "testmodel.php" . But suppose after sometime you want to move your project to another machine then you there you will get error. Because system will never find the above path.
So, what is the solution???
Think...
Think...
Again Think...
Ya, you got it. You need to provide relative path. Yii framework provides very good solution for this. Now you can refer the above describe alias path.
Solution : application.module.model.testmodel.php
I think it is clear for you. Now come to the core question. How we can generate models/crud/form under a modules.
- Create a module using Gii tool.
- Register your module name in the config main.php
- Create a model via Model Generator. Fill in the fields and put this in Model Path : application.modules.[module-name].models
- Create crud via Crud Generator. Fill in the fields and put this in Model Class: application.modules.[module-name].models.[model-name]
The above example was for models. Similarly you can use for crud or form.
when we create crud using the above method, view files are created in application view. i want to create the view files in the view folder of module. can you please help me out on this.
ReplyDeleteyou have to use [module-name]/yourControllername in controller field
Delete