To execute a console command open your terminal and change into the base directory of your LUYA project. The base directory is where folders like
runtime are located, e.g. when you run the luya-kickstarter it's in
On Windows systems you can run commands from the
public_htmlfolder and run:
php index.php <command>
Where command is one of the following commands below:
Standard built in commands
Global LUYA commands:
|Updates permission, CMS blocks, CMS layouts, image filters. Import is one of the main concepts of LUYA. It's saving your project data into the database. This way you can track your files within VCS (Git, SVN) and import them. Create Import Command.
|Execute all migrations from all modules, updates your database if any. The main difference to the Yii migrate command is it's going to collect all migrations from all modules.
migrate/create migration1 modulename
|Create new migration file named
mymigration1 in the module
migrate/create mymigration1 modulename.
|Tests all basic directory if they are writable and existing.
|Check if you mailer component is working and can send mails.
|Create new frontend/admin module with a wizard.
|All commands stored in the folder
commands can be run by default routing.
|Create new theme with a wizard.
Admin UI commands:
|Execute the LUYA Setup will create a user, group and base table informations.
|Create a new user for the LUYA admin UI from command line.
|Generate a Filter Class.
|Start the content sync process.
|Flush the configuration setup for the content sync process.
|Find if duplications are available in the image table (same filter and file id). If confirmed it will remove all duplications except of one, the first one created.
|Create all thumbnails for filemanager preview. Otherwise they are created on request load.
|Generate a new Active Window class file based on your configuration.
|Create new NgRest CRUD with a wizard.
|Generates only the NgRestModel. Usage
./vendor/bin/luya admin/crud/model "app\models\Customer"
CMS module commands:
|Create new CMS content blocks with a wizard.
Create your own command
You can create your own custom commands. Custom commands are stored as actions of controllers in the
commands directory of a module. Commands can only be executed from the console and do not have view files to render.
Let's assume you have a module
yourmodule with a controller
NotifyController that includes two actions
actionBar (stored in the file
NotifyController.php within the
commands directory of your module):
class NotifyController extends \luya\console\Command
public function actionIndex()
return $this->outputSuccess('Action successfully done');
public function actionBar()
return $this->outputError('Something failed inside this action');
outputSuccess($message)to return the status of the execution inside of the command, depending on this output we can handle PHPUnit test and return colorized outputs.
To run the
actionIndex() from the above mentioned
NotifyController controller in the
to execute the
actionBar() we have to change the route for the notify controller:
If you want to create a command without a module you can just add the command controller into the
commands folder of your application and add the controller to your
controllerMap of your configuration like the example below:
'controllerMap' => [
'sync' => 'app\commands\SyncController',
Now you could run the sync command like all other commands with
Views and UrlManger
Its very often case where you like to render a view and send a mail inside a console command, like batch processing some data (newsletter for example). Therefore your views use the luya\helpers\Url class in order to generate urls.
As the console command does not know your web server URL and there is no parameter of your web server url, therefore LUYA has a special configuration property called luya\traits\ApplicationTrait -> $consoleHostInfo.
This value will be used when defined as base URL for the urlManager.
'consoleHostInfo' => 'https://luya.io',