ControllerTrait ​
- Type
- Trait
- Namespace
- craft\console
- Implemented by
- craft\console\Controller, craft\console\controllers\BackupController, craft\console\controllers\BaseSystemStatusController, craft\console\controllers\ClearCachesController, craft\console\controllers\ClearDeprecationsController, craft\console\controllers\DbController, craft\console\controllers\ElementsController, craft\console\controllers\EntrifyController, craft\console\controllers\EntryTypesController, craft\console\controllers\EnvController, craft\console\controllers\ExecController, craft\console\controllers\FieldsController, craft\console\controllers\FixtureController, craft\console\controllers\GcController, craft\console\controllers\GraphqlController, craft\console\controllers\IndexAssetsController, craft\console\controllers\InstallController, craft\console\controllers\InvalidateTagsController, craft\console\controllers\MailerController, craft\console\controllers\MigrateController, craft\console\controllers\OffController, craft\console\controllers\OnController, craft\console\controllers\PcController, craft\console\controllers\PluginController, craft\console\controllers\ProjectConfigController, craft\console\controllers\ResaveController, craft\console\controllers\RestoreController, craft\console\controllers\SectionsController, craft\console\controllers\ServeController, craft\console\controllers\SetupController, craft\console\controllers\TestsController, craft\console\controllers\UpController, craft\console\controllers\UpdateController, craft\console\controllers\UsersController, craft\console\controllers\utils\AsciiFilenamesController, craft\console\controllers\utils\FixElementUidsController, craft\console\controllers\utils\FixFieldLayoutUidsController, craft\console\controllers\utils\PruneOrphanedEntriesController, craft\console\controllers\utils\PruneProvisionalDraftsController, craft\console\controllers\utils\PruneRevisionsController, craft\console\controllers\utils\RepairController, craft\console\controllers\utils\UpdateUsernamesController, craft\queue\Command
- Since
- 3.2.0
ConsoleControllerTrait implements the common methods and properties for console controllers.
Public Properties ​
Property | Description |
---|---|
isolated | – Whether the command should ensure it is only being run once at a time. |
isolated
​
- Default value
false
- Since
- 4.4.0
If this is passed and the same command is already being run in a separate shell/environment, the command will abort with an exit code of 1.
Public Methods ​
Method | Description |
---|---|
beforeAction() | This method is invoked right before an action is executed. |
failure() | Outputs a failure message to the console. |
init() | Initializes the object. |
markdownToAnsi() | Converts Markdown to be better readable in console environments by applying some ANSI format. |
note() | Outputs a note to the console. |
options() | Returns the names of valid options for the action (id). |
runAction() | Runs an action within this controller with the specified action ID and parameters. |
success() | Outputs a success message to the console. |
tip() | Outputs a tip to the console. |
warning() | Outputs a warning to the console. |
beforeAction()
​
- Since
- 4.4.0
This method is invoked right before an action is executed.
See also yii\base\Controller::beforeAction()View source
Arguments ​
$action
(yii\base\Action) – The action to be executed.
Returns ​
boolean – Whether the action should continue to run.
failure()
​
- Since
- 4.4.0
Outputs a failure message to the console.
Arguments ​
$message
(string) – The message. Supports Markdown formatting.
init()
​
- Since
- 4.4.0
Initializes the object.
See also yii\base\BaseObject::init()View source
markdownToAnsi()
​
- Since
- 4.4.0
Converts Markdown to be better readable in console environments by applying some ANSI format.
Arguments ​
$markdown
(string)
Returns ​
note()
​
- Since
- 4.4.0
Outputs a note to the console.
Arguments ​
$message
(string) – The message. Supports Markdown formatting.$icon
options()
​
- Since
- 4.4.0
Returns the names of valid options for the action (id).
See also yii\console\Controller::options()View source
Arguments ​
$actionID
(string) – The action ID of the current request.
Returns ​
string[] – The names of the options valid for the action.
runAction()
​
- Since
- 4.4.0
Runs an action within this controller with the specified action ID and parameters.
Runs an action with the specified action ID and parameters. If the action ID is empty, the method will use \craft\console\defaultAction
.
See also yii\console\Controller::runAction()View source
Arguments ​
$id
(string) – The ID of the action to be executed.$params
(array) – The parameters (name-value pairs) to be passed to the action.
Returns ​
integer – The status of the action execution. 0 means normal, other values mean abnormal.
Throws ​
- yii\base\InvalidRouteException
if the requested action ID cannot be resolved into an action successfully. - yii\console\Exception
if there are unknown options or missing arguments
success()
​
- Since
- 4.4.0
Outputs a success message to the console.
Arguments ​
$message
(string) – The message. Supports Markdown formatting.
tip()
​
- Since
- 4.4.0
Outputs a tip to the console.
Arguments ​
$message
(string) – The message. Supports Markdown formatting.
warning()
​
- Since
- 4.4.0
Outputs a warning to the console.
Arguments ​
$message
(string) – The message. Supports Markdown formatting.
Protected Methods ​
Method | Description |
---|---|
checkRootUser() | Returns whether a command should be executed depending on whether it's being run as a root user, and whether they're OK with that. |
checkTty() | Sets yii\console\Controller::$interactive to false if this isn’t a TTY shell. |
createAttributeValidator() | Creates a function for the validator option of Controller::prompt . |
outputCommand() |
checkRootUser()
​
- Since
- 3.7.0
Returns whether a command should be executed depending on whether it's being run as a root user, and whether they're OK with that.
Returns ​
checkTty()
​
- Since
- 3.6.1
Sets yii\console\Controller::$interactive to false
if this isn’t a TTY shell.
createAttributeValidator()
​
- Since
- 3.7.0
Creates a function for the validator
option of Controller::prompt
.
Arguments ​
$model
(craft\base\Model)$attribute
(string)