php-yii

Yii framework console command runner

TLDR

List available commands
$ php yii help
Run database migrations
$ php yii migrate
Create a new migration
$ php yii migrate/create [create_users_table]
Rollback last migration
$ php yii migrate/down
Generate model from table
$ php yii gii/model --tableName=[table] --modelClass=[ModelName]
Generate CRUD
$ php yii gii/crud --modelClass=[app\\models\\Post]
Clear all caches
$ php yii cache/flush-all
Get help for a specific command
$ php yii help [migrate]

SYNOPSIS

php yii [command] [--option=value...]

DESCRIPTION

yii is the console entry point for Yii 2.0 PHP framework applications. It provides access to built-in commands for database migrations, code generation, caching, asset management, and application serving.Console commands use the route format controller/action (e.g., migrate/create). Options are passed as --option=value. Custom console commands can be created by extending yii\console\Controller.The gii commands provide code generation capabilities for models, controllers, CRUD interfaces, forms, modules, and extensions. The migrate commands manage database schema changes through versioned migration files.

PARAMETERS

--tableName name

Database table name (gii/model).
--modelClass class
Model class name (gii/model, gii/crud).
--interactive 0|1
Run in non-interactive mode. Default: 1.
--color 0|1
Enable/disable ANSI color output.

SUBCOMMANDS

help [command]

Show available commands or help for a specific command.
migrate
Run pending database migrations.
migrate/create name
Create a new migration file.
migrate/down [count]
Rollback migrations. Default: 1.
migrate/redo [count]
Redo migrations (down then up).
gii/model
Generate model class from database table.
gii/crud
Generate CRUD controller and views.
gii/controller
Generate controller class.
cache/flush-all
Clear all application caches.
cache/flush component
Flush a specific cache component.
asset/compress configFile bundleFile
Combine and compress JavaScript and CSS files.
serve
Run PHP built-in web server.

INSTALL

sudo dnf install php
sudo pacman -S php
sudo apk add php85
brew install php
nix profile install nixpkgs#php85

CAVEATS

Must be run from the project root directory where the yii bootstrap file exists. Requires a properly configured Yii 2.0 application. Some commands like gii require the yii2-gii extension. Database commands require configured database connection.

HISTORY

The Yii console was introduced with Yii 2.0, released in 2014 by Qiang Xue. The console runner replaced the yiic tool from Yii 1.x with a more flexible command architecture.

SEE ALSO

php(1), composer(1), artisan(1), symfony(1)