# Controller

> Controller is the base class of console command classes.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [console](/docs/api/yii/console/index.md) › Controller

| class | `yii\console\Controller` |
| --- | --- |
| Extends | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\ViewContextInterface`](/docs/api/yii/base/viewcontextinterface/index.md), [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/console/Controller.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/console/Controller.php#L53) |

7 subclasses:

- [`yii\console\controllers\AssetController`](/docs/api/yii/console/controllers/assetcontroller/index.md)
- [`yii\console\controllers\BaseMigrateController`](/docs/api/yii/console/controllers/basemigratecontroller/index.md)
- [`yii\console\controllers\CacheController`](/docs/api/yii/console/controllers/cachecontroller/index.md)
- [`yii\console\controllers\FixtureController`](/docs/api/yii/console/controllers/fixturecontroller/index.md)
- [`yii\console\controllers\HelpController`](/docs/api/yii/console/controllers/helpcontroller/index.md)
- [`yii\console\controllers\MessageController`](/docs/api/yii/console/controllers/messagecontroller/index.md)
- [`yii\console\controllers\ServeController`](/docs/api/yii/console/controllers/servecontroller/index.md)

Controller is the base class of console command classes.

A console controller consists of one or several actions known as sub-commands.
Users call a console command by specifying the corresponding route which identifies a controller action.
The `yii` program is used when calling a console command, like the following:

```
yii <route> [--param1=value1 --param2 ...]
```

where `<route>` is a route to a controller action and the params will be populated as properties of a command.
See [`options()`](/docs/api/yii/console/controller/index.md#method-options) for details.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-action"></span>[`$action`](/docs/api/yii/base/controller/index.md#property-action) | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>\|null` | The action that is currently being executed. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`$color`](#property-color) | `bool\|null` | Whether to enable ANSI color in the output. Default: `null`. | `Controller` |
| <span id="property-defaultAction"></span>[`$defaultAction`](/docs/api/yii/base/controller/index.md#property-defaultAction) | `string` | The ID of the action that is used when the action ID is not specified in the request. Default: `'index'`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-help"></span>`$help` | `bool` | Whether to display help information about current command. Default: `false`. Available since 2.0.10. | `Controller` |
| <span id="property-helpSummary"></span>`$helpSummary` read-only | `string` | The one-line short summary describing this controller. | `Controller` |
| <span id="property-id"></span>[`$id`](/docs/api/yii/base/controller/index.md#property-id) | `string` | The ID of this controller. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-interactive"></span>`$interactive` | `bool` | Whether to run the command interactively. Default: `true`. | `Controller` |
| <span id="property-layout"></span>[`$layout`](/docs/api/yii/base/controller/index.md#property-layout) | `string\|null\|false` | The name of the layout to be applied to this controller's views. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-module"></span>[`$module`](/docs/api/yii/base/controller/index.md#property-module) | `yii\base\T` | The module that this controller belongs to. Default: `null`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-modules"></span>[`$modules`](/docs/api/yii/base/controller/index.md#property-modules) read-only | [`yii\base\Module`](/docs/api/yii/base/module/index.md)`[]` | All ancestor modules that this controller is located within. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-passedOptions"></span>`$passedOptions` read-only | `array` | The names of the options passed during execution. | `Controller` |
| <span id="property-passedOptionValues"></span>`$passedOptionValues` read-only | `array` | The properties corresponding to the passed options. | `Controller` |
| <span id="property-request"></span>`$request` | [`Request`](/docs/api/yii/console/request/index.md) | The request object. | `Controller` |
| <span id="property-response"></span>`$response` | [`Response`](/docs/api/yii/console/response/index.md) | The response object. | `Controller` |
| <span id="property-route"></span>[`$route`](/docs/api/yii/base/controller/index.md#property-route) read-only | `string` | The route (module ID, controller ID and action ID) of the current request. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`$silentExitOnException`](#property-silentExitOnException) | `bool\|null` | If true - script finish with `ExitCode::OK` in case of exception. false - `ExitCode::UNSPECIFIED_ERROR`. Default: `null`. Available since 2.0.36. | `Controller` |
| <span id="property-uniqueId"></span>[`$uniqueId`](/docs/api/yii/base/controller/index.md#property-uniqueId) read-only | `string` | The controller ID that is prefixed with the module ID (if any). | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-view"></span>[`$view`](/docs/api/yii/base/controller/index.md#property-view) | [`yii\base\View`](/docs/api/yii/base/view/index.md)`\|`[`yii\web\View`](/docs/api/yii/web/view/index.md) | The view object that can be used to render views or view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="property-viewPath"></span>[`$viewPath`](/docs/api/yii/base/controller/index.md#property-viewPath) | `string` | The directory containing the view files for this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/base/controller/index.md#method-__construct) |  | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-actions"></span>[`actions()`](/docs/api/yii/base/controller/index.md#method-actions) | Declares external actions for the controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-afterAction"></span>[`afterAction()`](/docs/api/yii/base/controller/index.md#method-afterAction) | This method is invoked right after an action is executed. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`ansiFormat()`](#method-ansiFormat) | Formats a string with ANSI codes. | `Controller` |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`beforeAction()`](#method-beforeAction) | This method is invoked right before an action is executed. | `Controller` |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`bindActionParams()`](#method-bindActionParams) | Binds the parameters to the action. | `Controller` |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`confirm()`](#method-confirm) | Asks user to confirm by typing y or n. | `Controller` |
| <span id="method-createAction"></span>[`createAction()`](/docs/api/yii/base/controller/index.md#method-createAction) | Creates an action based on the given action ID. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-findLayoutFile"></span>[`findLayoutFile()`](/docs/api/yii/base/controller/index.md#method-findLayoutFile) | Finds the applicable layout file. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`getActionArgsHelp()`](#method-getActionArgsHelp) | Returns the help information for the anonymous arguments for the action. | `Controller` |
| [`getActionHelp()`](#method-getActionHelp) | Returns the detailed help information for the specified action. | `Controller` |
| [`getActionHelpSummary()`](#method-getActionHelpSummary) | Returns a one-line short summary describing the specified action. | `Controller` |
| [`getActionOptionsHelp()`](#method-getActionOptionsHelp) | Returns the help information for the options for the action. | `Controller` |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`getHelp()`](#method-getHelp) | Returns help information for this controller. | `Controller` |
| [`getHelpSummary()`](#method-getHelpSummary) | Returns one-line short summary describing this controller. | `Controller` |
| <span id="method-getModules"></span>[`getModules()`](/docs/api/yii/base/controller/index.md#method-getModules) | Returns all ancestor modules of this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`getOptionValues()`](#method-getOptionValues) | Returns properties corresponding to the options for the action id Child classes may override this method to specify possible properties. | `Controller` |
| [`getPassedOptions()`](#method-getPassedOptions) | Returns the names of valid options passed during execution. | `Controller` |
| [`getPassedOptionValues()`](#method-getPassedOptionValues) | Returns the properties corresponding to the passed options. | `Controller` |
| <span id="method-getRoute"></span>[`getRoute()`](/docs/api/yii/base/controller/index.md#method-getRoute) | Returns the route of the current request. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getUniqueId"></span>[`getUniqueId()`](/docs/api/yii/base/controller/index.md#method-getUniqueId) | Returns the unique ID of the controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getView"></span>[`getView()`](/docs/api/yii/base/controller/index.md#method-getView) | Returns the view object that can be used to render views or view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-getViewPath"></span>[`getViewPath()`](/docs/api/yii/base/controller/index.md#method-getViewPath) | Returns the directory containing view files for this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/controller/index.md#method-init) | Initializes the object. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`isColorEnabled()`](#method-isColorEnabled) | Returns a value indicating whether ANSI color is enabled. | `Controller` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`optionAliases()`](#method-optionAliases) | Returns option alias names. | `Controller` |
| [`options()`](#method-options) | Returns the names of valid options for the action (id) An option requires the existence of a public member variable whose name is the option name. | `Controller` |
| [`prompt()`](#method-prompt) | Prompts the user for input and validates it. | `Controller` |
| <span id="method-render"></span>[`render()`](/docs/api/yii/base/controller/index.md#method-render) | Renders a view and applies layout if available. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderContent"></span>[`renderContent()`](/docs/api/yii/base/controller/index.md#method-renderContent) | Renders a static string by applying a layout. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderFile"></span>[`renderFile()`](/docs/api/yii/base/controller/index.md#method-renderFile) | Renders a view file. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-renderPartial"></span>[`renderPartial()`](/docs/api/yii/base/controller/index.md#method-renderPartial) | Renders a view without applying layout. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-run"></span>[`run()`](/docs/api/yii/base/controller/index.md#method-run) | Runs a request specified in terms of a route. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`runAction()`](#method-runAction) | Runs an action with the specified action ID and parameters. | `Controller` |
| [`select()`](#method-select) | Gives the user an option to choose from. Giving '?' as an input will show a list of options to choose from and their explanations. | `Controller` |
| <span id="method-setView"></span>[`setView()`](/docs/api/yii/base/controller/index.md#method-setView) | Sets the view object to be used by this controller. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="method-setViewPath"></span>[`setViewPath()`](/docs/api/yii/base/controller/index.md#method-setViewPath) | Sets the directory that contains the view files. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`stderr()`](#method-stderr) | Prints a string to STDERR. | `Controller` |
| [`stdout()`](#method-stdout) | Prints a string to STDOUT. | `Controller` |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-bindInjectedParams"></span>[`bindInjectedParams()`](/docs/api/yii/base/controller/index.md#method-bindInjectedParams) protected final | Fills parameters based on types and names in action method signature. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| [`getActionMethodReflection()`](#method-getActionMethodReflection) protected |  | `Controller` |
| [`parseDocCommentDetail()`](#method-parseDocCommentDetail) protected | Returns full description from the docblock. | `Controller` |
| [`parseDocCommentSummary()`](#method-parseDocCommentSummary) protected | Returns the first line of docblock. | `Controller` |
| [`parseDocCommentTags()`](#method-parseDocCommentTags) protected | Parses the comment block into tags. | `Controller` |

## Events

| Event | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="event-EVENT_BEFORE_ACTION"></span>[`EVENT_BEFORE_ACTION`](/docs/api/yii/base/controller/index.md#event-EVENT_BEFORE_ACTION) | [`yii\base\ActionEvent`](/docs/api/yii/base/actionevent/index.md) | An event raised right before executing a controller action. Event name: `'beforeAction'`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |
| <span id="event-EVENT_AFTER_ACTION"></span>[`EVENT_AFTER_ACTION`](/docs/api/yii/base/controller/index.md#event-EVENT_AFTER_ACTION) | [`yii\base\ActionEvent`](/docs/api/yii/base/actionevent/index.md) | An event raised right after executing a controller action. Event name: `'afterAction'`. | [`yii\base\Controller`](/docs/api/yii/base/controller/index.md) |

## Property details

### $color <span id="property-color"></span>

```php
public bool|null $color = null
```

Whether to enable ANSI color in the output.

If not set, ANSI color will only be enabled for terminals that support it.

### $silentExitOnException <span id="property-silentExitOnException"></span>

```php
public bool|null $silentExitOnException = null
```

If true - script finish with `ExitCode::OK` in case of exception. false - `ExitCode::UNSPECIFIED_ERROR`.

Default: `YII_ENV_TEST`

**Since**

2.0.36

## Method details

### ansiFormat() <span id="method-ansiFormat"></span>

```php
public function ansiFormat(string $string): string
```

Formats a string with ANSI codes.

You may pass additional parameters using the constants defined in [`Console`](/docs/api/yii/helpers/console/index.md).

Example:

```
echo $this->ansiFormat('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$string` | `string` | The string to be formatted |

**Returns**

`string`

### beforeAction() <span id="method-beforeAction"></span>

```php
public function beforeAction(mixed $action): bool
```

This method is invoked right before an action is executed.

The method will trigger the [`EVENT_BEFORE_ACTION`](/docs/api/yii/base/controller/index.md#event-EVENT_BEFORE_ACTION) event. The return value of the method
will determine whether the action should continue to run.

In case the action should not run, the request should be handled inside of the `beforeAction` code
by either providing the necessary output or redirecting the request. Otherwise the response will be empty.

If you override this method, your code should look like the following:

```
public function beforeAction($action)
{
    // your custom code here, if you want the code to run before action filters,
    // which are triggered on the [[EVENT_BEFORE_ACTION]] event, e.g. PageCache or AccessControl

    if (!parent::beforeAction($action)) {
        return false;
    }

    // other custom code here

    return true; // or false to not run the action
}
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | `mixed` | The action to be executed. |

**Returns**

`bool`: Whether the action should continue to run.

### bindActionParams() <span id="method-bindActionParams"></span>

```php
public function bindActionParams(yii\base\Action<static> $action, array<array-key, mixed> $params): mixed[]
```

Binds the parameters to the action.

This method is invoked by [`Action`](/docs/api/yii/base/action/index.md) when it begins to run with the given parameters.
This method will first bind the parameters with the [options](/docs/api/yii/console/controller/index.md#method-options)
available to the action. It then validates the given arguments.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>` | The action to be bound with parameters |
| `$params` | `array<array-key, mixed>` | The parameters to be bound to the action |

**Returns**

`mixed[]`: The valid parameters that the action can run with.

**Throws**

- [`Exception`](/docs/api/yii/console/exception/index.md): if there are unknown options or missing arguments

### confirm() <span id="method-confirm"></span>

```php
public function confirm(string $message, bool $default = false): bool
```

Asks user to confirm by typing y or n.

A typical usage looks like the following:

```
if ($this->confirm("Are you sure?")) {
    echo "user typed yes\n";
} else {
    echo "user typed no\n";
}
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$message` | `string` | To echo out before waiting for user input |
| `$default` | `bool` | This value is returned if no selection is made. |

**Returns**

`bool`: Whether user confirmed. Will return true if [`$interactive`](/docs/api/yii/console/controller/index.md#property-interactive) is false.

### getActionArgsHelp() <span id="method-getActionArgsHelp"></span>

```php
public function getActionArgsHelp(yii\base\Action<static> $action): array
```

Returns the help information for the anonymous arguments for the action.

The returned value should be an array. The keys are the argument names, and the values are the corresponding help
information. Each value must be an array of the following structure:

- required: bool, whether this argument is required.
- type: string|null, the PHP type(s) of this argument.
- default: mixed, the default value of this argument.
- comment: string, the description of this argument.

The default implementation will return the help information extracted from the Reflection or DocBlock of the
parameters corresponding to the action method.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>` | The action instance |

**Returns**

`array`: The help information of the action arguments

### getActionHelp() <span id="method-getActionHelp"></span>

```php
public function getActionHelp(yii\base\Action<static> $action): string
```

Returns the detailed help information for the specified action.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>` | Action to get help for |

**Returns**

`string`: The detailed help information for the specified action.

### getActionHelpSummary() <span id="method-getActionHelpSummary"></span>

```php
public function getActionHelpSummary(yii\base\Action<static> $action): string
```

Returns a one-line short summary describing the specified action.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>` | Action to get summary for |

**Returns**

`string`: A one-line short summary describing the specified action.

### getActionOptionsHelp() <span id="method-getActionOptionsHelp"></span>

```php
public function getActionOptionsHelp(yii\base\Action<static> $action): array
```

Returns the help information for the options for the action.

The returned value should be an array. The keys are the option names, and the values are
the corresponding help information. Each value must be an array of the following structure:

- type: string, the PHP type of this argument.
- default: string, the default value of this argument
- comment: string, the comment of this argument

The default implementation will return the help information extracted from the doc-comment of
the properties corresponding to the action options.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>` |  |

**Returns**

`array`: The help information of the action options

### getHelp() <span id="method-getHelp"></span>

```php
public function getHelp(): string
```

Returns help information for this controller.

You may override this method to return customized help.
The default implementation returns help information retrieved from the PHPDoc comment.

**Returns**

`string`: The help information for this controller.

### getHelpSummary() <span id="method-getHelpSummary"></span>

```php
public function getHelpSummary(): string
```

Returns one-line short summary describing this controller.

You may override this method to return customized summary.
The default implementation returns first line from the PHPDoc comment.

**Returns**

`string`: The one-line short summary describing this controller.

### getOptionValues() <span id="method-getOptionValues"></span>

```php
public function getOptionValues(string $actionID): array
```

Returns properties corresponding to the options for the action id
Child classes may override this method to specify possible properties.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$actionID` | `string` | The action id of the current request |

**Returns**

`array`: Properties corresponding to the options for the action

### getPassedOptions() <span id="method-getPassedOptions"></span>

```php
public function getPassedOptions(): array
```

Returns the names of valid options passed during execution.

**Returns**

`array`: The names of the options passed during execution

### getPassedOptionValues() <span id="method-getPassedOptionValues"></span>

```php
public function getPassedOptionValues(): array
```

Returns the properties corresponding to the passed options.

**Returns**

`array`: The properties corresponding to the passed options

### isColorEnabled() <span id="method-isColorEnabled"></span>

```php
public function isColorEnabled(resource $stream = \STDOUT): bool
```

Returns a value indicating whether ANSI color is enabled.

ANSI color is enabled only if [`$color`](/docs/api/yii/console/controller/index.md#property-color) is set true or is not set
and the terminal supports ANSI color.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$stream` | `resource` | The stream to check. |

**Returns**

`bool`: Whether to enable ANSI style in output.

### optionAliases() <span id="method-optionAliases"></span>

```php
public function optionAliases(): array
```

Returns option alias names.

Child classes may override this method to specify alias options.

**Returns**

`array`: The options alias names valid for the action where the keys is alias name for option and value is option name.

**Since**

2.0.8

**See also**

- [`options()`](/docs/api/yii/console/controller/index.md#method-options)

### options() <span id="method-options"></span>

```php
public function options(string $actionID): string[]
```

Returns the names of valid options for the action (id)
An option requires the existence of a public member variable whose
name is the option name.

Child classes may override this method to specify possible options.

Note that the values setting via options are not available
until [`beforeAction()`](/docs/api/yii/console/controller/index.md#method-beforeAction) is being called.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$actionID` | `string` | The action id of the current request |

**Returns**

`string[]`: The names of the options valid for the action

### prompt() <span id="method-prompt"></span>

```php
public function prompt(string $text, array $options = []): string
```

Prompts the user for input and validates it.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$text` | `string` | Prompt string |
| `$options` | `array` | The options to validate the input: - required: whether it is required or not - default: default value if no input is inserted by the user - pattern: regular expression pattern to validate user input - validator: a callable function to validate input. The function must accept two parameters: - $input: the user input to validate - $error: the error value passed by reference if validation failed. An example of how to use the prompt method with a validator function. $code = $this->prompt('Enter 4-Chars-Pin', ['required' => true, 'validator' => function($input, &$error) { if (strlen($input) !== 4) { $error = 'The Pin must be exactly 4 chars!'; return false; } return true; }]); |

**Returns**

`string`: The user input

### runAction() <span id="method-runAction"></span>

```php
public function runAction(string $id, array $params = []): mixed
```

Runs an action with the specified action ID and parameters.

If the action ID is empty, the method will use [`$defaultAction`](/docs/api/yii/base/controller/index.md#property-defaultAction).

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$id` | `string` | The ID of the action to be executed. |
| `$params` | `array` | The parameters (name-value pairs) to be passed to the action. |

**Returns**

`mixed`: The result of the action.

**Throws**

- [`yii\base\InvalidRouteException`](/docs/api/yii/base/invalidrouteexception/index.md): if the requested action ID cannot be resolved into an action successfully.
- [`Exception`](/docs/api/yii/console/exception/index.md): if there are unknown options or missing arguments

**See also**

- [`createAction()`](/docs/api/yii/base/controller/index.md#method-createAction)

### select() <span id="method-select"></span>

```php
public function select(string $prompt, array $options = [], string|null $default = null): string
```

Gives the user an option to choose from. Giving '?' as an input will show
a list of options to choose from and their explanations.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$prompt` | `string` | The prompt message |
| `$options` | `array` | Key-value array of options to choose from |
| `$default` | `string\|null` | Value to use when the user doesn't provide an option. If the default is `null`, the user is required to select an option. |

**Returns**

`string`: An option character the user chose

### stderr() <span id="method-stderr"></span>

```php
public function stderr(string $string): int|bool
```

Prints a string to STDERR.

You may optionally format the string with ANSI codes by
passing additional parameters using the constants defined in [`Console`](/docs/api/yii/helpers/console/index.md).

Example:

```
$this->stderr('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$string` | `string` | The string to print |

**Returns**

`int|bool`: Number of bytes printed or false on error

### stdout() <span id="method-stdout"></span>

```php
public function stdout(string $string): int|bool
```

Prints a string to STDOUT.

You may optionally format the string with ANSI codes by
passing additional parameters using the constants defined in [`Console`](/docs/api/yii/helpers/console/index.md).

Example:

```
$this->stdout('This will be red and underlined.', Console::FG_RED, Console::UNDERLINE);
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$string` | `string` | The string to print |

**Returns**

`int|bool`: Number of bytes printed or false on error

### getActionMethodReflection() <span id="method-getActionMethodReflection"></span>

```php
protected function getActionMethodReflection(yii\base\Action<static> $action): ReflectionFunctionAbstract
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$action` | [`yii\base\Action`](/docs/api/yii/base/action/index.md)`<static>` |  |

**Returns**

[`ReflectionFunctionAbstract`](https://www.php.net/manual/en/class.reflectionfunctionabstract.php)

### parseDocCommentDetail() <span id="method-parseDocCommentDetail"></span>

```php
protected function parseDocCommentDetail(ReflectionClass<static>|ReflectionProperty|ReflectionFunctionAbstract $reflection): string
```

Returns full description from the docblock.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$reflection` | [`ReflectionClass`](https://www.php.net/manual/en/class.reflectionclass.php)`<static>\|`[`ReflectionProperty`](https://www.php.net/manual/en/class.reflectionproperty.php)`\|`[`ReflectionFunctionAbstract`](https://www.php.net/manual/en/class.reflectionfunctionabstract.php) |  |

**Returns**

`string`

### parseDocCommentSummary() <span id="method-parseDocCommentSummary"></span>

```php
protected function parseDocCommentSummary(ReflectionClass<static>|ReflectionProperty|ReflectionFunctionAbstract $reflection): string
```

Returns the first line of docblock.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$reflection` | [`ReflectionClass`](https://www.php.net/manual/en/class.reflectionclass.php)`<static>\|`[`ReflectionProperty`](https://www.php.net/manual/en/class.reflectionproperty.php)`\|`[`ReflectionFunctionAbstract`](https://www.php.net/manual/en/class.reflectionfunctionabstract.php) |  |

**Returns**

`string`

### parseDocCommentTags() <span id="method-parseDocCommentTags"></span>

```php
protected function parseDocCommentTags(ReflectionClass<object>|ReflectionProperty|ReflectionFunctionAbstract $reflection): array
```

Parses the comment block into tags.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$reflection` | [`ReflectionClass`](https://www.php.net/manual/en/class.reflectionclass.php)`<object>\|`[`ReflectionProperty`](https://www.php.net/manual/en/class.reflectionproperty.php)`\|`[`ReflectionFunctionAbstract`](https://www.php.net/manual/en/class.reflectionfunctionabstract.php) | The comment block |

**Returns**

`array`: The parsed tags