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\ExecController, 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\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\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.
View source (opens new window)
# 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.
View source (opens new window)
# 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() (opens new window) View source (opens new window)
Arguments
$action
(yii\base\Action (opens new window)) – The action to be executed.
Returns
boolean (opens new window) – Whether the action should continue to run.
# failure()
- Since
- 4.4.0
Outputs a failure message to the console.
View source (opens new window)
Arguments
$message
(string (opens new window)) – The message. Supports Markdown formatting.
# init()
- Since
- 4.4.0
Initializes the object.
See also yii\base\BaseObject::init() (opens new window) View source (opens new window)
# markdownToAnsi()
- Since
- 4.4.0
Converts Markdown to be better readable in console environments by applying some ANSI format.
View source (opens new window)
Arguments
$markdown
(string (opens new window))
Returns
# note()
- Since
- 4.4.0
Outputs a note to the console.
View source (opens new window)
Arguments
$message
(string (opens new window)) – 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() (opens new window) View source (opens new window)
Arguments
$actionID
(string (opens new window)) – The action ID of the current request.
Returns
string (opens new window)[] – 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() (opens new window) View source (opens new window)
Arguments
$id
(string (opens new window)) – The ID of the action to be executed.$params
(array (opens new window)) – The parameters (name-value pairs) to be passed to the action.
Returns
integer (opens new window) – The status of the action execution. 0 means normal, other values mean abnormal.
Throws
- yii\base\InvalidRouteException (opens new window)
if the requested action ID cannot be resolved into an action successfully. - yii\console\Exception (opens new window)
if there are unknown options or missing arguments
# success()
- Since
- 4.4.0
Outputs a success message to the console.
View source (opens new window)
Arguments
$message
(string (opens new window)) – The message. Supports Markdown formatting.
# tip()
- Since
- 4.4.0
Outputs a tip to the console.
View source (opens new window)
Arguments
$message
(string (opens new window)) – The message. Supports Markdown formatting.
# warning()
- Since
- 4.4.0
Outputs a warning to the console.
View source (opens new window)
Arguments
$message
(string (opens new window)) – 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 (opens new window) 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.
View source (opens new window)
Returns
# checkTty()
- Since
- 3.6.1
Sets yii\console\Controller::$interactive (opens new window) to false
if this isn’t a TTY shell.
View source (opens new window)
# createAttributeValidator()
- Since
- 3.7.0
Creates a function for the validator
option of Controller::prompt
.
View source (opens new window)
Arguments
$model
(craft\base\Model)$attribute
(string (opens new window))
Returns
# outputCommand()
View source (opens new window)
Arguments
$command
(string (opens new window))$withScriptName
(boolean (opens new window))