For debugging and multiple one-off commands, you can enter the CLI container with
docker-compose run --rm -e YII_ENV=dev php bash
💡 Code generation only work in Yii's development environment.
You can create a standard Yii module with
$ yii gii/module \
--moduleID=frontend \
--moduleClass=app\\modules\\frontend\\Module
Create additional controller
$ yii gii/controller \
--controllerClass=app\\modules\\frontend\\controllers\\ExamplesController \
--viewPath=@app/modules/frontend/views/examples
To add it to your application adjust configuration in src/config/common.php.
return [
'modules' => [
'frontend' => [
'class' => 'app\modules\frontend\Module',
'layout' => '//container',
]
]
];
You should now be able to access to module default page via /frontend in your browser.
phd allows you to use you custom designed database schema as the base for CRUD admin interfaces.
To add a new module to your application, we create a crud module with phd and Yii's built-in tools
If you would like to create an extension module in a composer package, please start by creating an extension first. push it to your repo and install it with
composer require --prefer-source name/package. Afterwards generate your code directly intovendor/name/packageand use this repository for development.
$ yii gii/giiant-module \
--moduleID=crud \
--moduleClass=app\\modules\\crud\\Module
To add it to your application adjust your configuration in src/config/common.php.
return [
'modules' => [
'crud' => [
'class' => 'app\modules\crud\Module',
'layout' => '@admin-views/layouts/main',
]
]
];
💡 When using a non-autoloaded namespace you need to register an alias before running the
giicommand'aliases' => [ '@name/package' => '@app/modules/crud' ],
$ yii migrate/create init --migrationPath=@app/modules/crud/migrations
Add migration to application params in src/config/common.php
'params' => [
'yii.migrations' => [
'@app/modules/crud/migrations'
],
],
And run the migrations
$ yii migrate
See also how to create file migrations.
Create the backend CRUDs with gii and Giiant
yii giiant-batch \
--interactive=0 \
--overwrite=1 \
--modelDb=db \
--modelNamespace=app\\modules\\crud\\models \
--modelQueryNamespace=app\\modules\\crud\\models\\query \
--crudAccessFilter=1 \
--crudControllerNamespace=app\\modules\\crud\\controllers \
--crudSearchModelNamespace=app\\modules\\crud\\models\\search \
--crudViewPath=@app/modules/crud/views \
--crudPathPrefix= \
--tablePrefix=<PREFIX_> \
--tables=<COMMA_SEPARATED_LIST_OF_TABLES>
See also Giiant documentation.
Have also a look at guidelines for good schema design even if it was written for Yii 1 it is still valid today.
Login to the application backend as admin and go to the crud module.
💡 You can define and register the batch command in the Module bootstrapping process.