Class yii\gii\generators\controller\Generator

Inheritanceyii\gii\generators\controller\Generator » yii\gii\Generator » yii\base\Model
Available since version2.0

This generator will generate a controller and one or a few action view files.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$actions string List of action IDs separated by commas or spaces yii\gii\generators\controller\Generator
$baseClass string The base class of the controller yii\gii\generators\controller\Generator
$controllerClass string The controller class name yii\gii\generators\controller\Generator
$enableI18N boolean Whether the strings will be generated using Yii::t() or normal strings. yii\gii\Generator
$messageCategory string The message category used by Yii::t() when $enableI18N is true. yii\gii\Generator
$template string The name of the code template that the user has selected. yii\gii\Generator
$templates array A list of available code templates. yii\gii\Generator
$viewPath string The controller's view path yii\gii\generators\controller\Generator

Public Methods

Hide inherited methods

MethodDescriptionDefined By
attributeLabels() yii\gii\generators\controller\Generator
autoCompleteData() Returns the list of auto complete values. yii\gii\Generator
defaultTemplate() Returns the root path to the default code template files. yii\gii\Generator
formView() Returns the view file for the input form of the generator. yii\gii\Generator
generate() Generates the code based on the current user input and the specified code template files. yii\gii\generators\controller\Generator
generateString() Generates a string depending on enableI18N property yii\gii\Generator
getActionIDs() Normalizes $actions into an array of action IDs. yii\gii\generators\controller\Generator
getControllerFile() yii\gii\generators\controller\Generator
getControllerID() yii\gii\generators\controller\Generator
getControllerNamespace() yii\gii\generators\controller\Generator
getControllerSubPath() This method will return sub path for controller if it is located in subdirectory of application controllers dir yii\gii\generators\controller\Generator
getDescription() yii\gii\generators\controller\Generator
getName() yii\gii\generators\controller\Generator
getStickyDataFile() yii\gii\Generator
getTemplatePath() yii\gii\Generator
getViewFile() yii\gii\generators\controller\Generator
hints() Returns the list of hint messages. yii\gii\generators\controller\Generator
init() yii\gii\Generator
isReservedKeyword() yii\gii\Generator
loadStickyAttributes() Loads sticky attributes from an internal file and populates them into the generator. yii\gii\Generator
render() Generates code using the specified code template and parameters. yii\gii\Generator
requiredTemplates() Returns a list of code template files that are required. yii\gii\generators\controller\Generator
rules() yii\gii\generators\controller\Generator
save() Saves the generated code into files. yii\gii\Generator
saveStickyAttributes() Saves sticky attributes into an internal file. yii\gii\Generator
stickyAttributes() Returns the list of sticky attributes. yii\gii\generators\controller\Generator
successMessage() Returns the message to be displayed when the newly generated code is saved successfully. yii\gii\generators\controller\Generator
validateClass() An inline validator that checks if the attribute value refers to an existing class name. yii\gii\Generator
validateMessageCategory() Checks if message category is not empty when I18N is enabled. yii\gii\Generator
validateNewClass() An inline validator that checks if the attribute value refers to a valid namespaced class name. yii\gii\Generator
validateTemplate() Validates the template selection. yii\gii\Generator

Property Details

$actions public property

List of action IDs separated by commas or spaces

public string $actions 'index'
$baseClass public property

The base class of the controller

public string $baseClass 'yii\web\Controller'
$controllerClass public property

The controller class name

public string $controllerClass null
$viewPath public property

The controller's view path

public string $viewPath null

Method Details

attributeLabels() public method

public void attributeLabels ( )
generate() public method

Generates the code based on the current user input and the specified code template files.

This is the main method that child classes should implement. Please refer to yii\gii\generators\controller\Generator::generate() as an example on how to implement this method.

public yii\gii\CodeFile[] generate ( )
return yii\gii\CodeFile[]

A list of code files to be created.

getActionIDs() public method

Normalizes $actions into an array of action IDs.

public array getActionIDs ( )
return array

An array of action IDs entered by the user

getControllerFile() public method

public string getControllerFile ( )
return string

The controller class file path

getControllerID() public method

public string getControllerID ( )
return string

The controller ID

getControllerNamespace() public method

public string getControllerNamespace ( )
return string

The namespace of the controller class

getControllerSubPath() public method (available since version 2.0.6)

This method will return sub path for controller if it is located in subdirectory of application controllers dir

See also https://github.com/yiisoft/yii2-gii/issues/182.

public string getControllerSubPath ( )
return string

The controller sub path

getDescription() public method

public string getDescription ( )
return string

The detailed description of the generator.

getName() public method

public string getName ( )
return string

Name of the code generator

getViewFile() public method

public string getViewFile ( $action )
$action string

The action ID

return string

The action view file path

hints() public method

Returns the list of hint messages.

The array keys are the attribute names, and the array values are the corresponding hint messages. Hint messages will be displayed to end users when they are filling the form for the generator.

public array hints ( )
return array

The list of hint messages

requiredTemplates() public method

Returns a list of code template files that are required.

Derived classes usually should override this method if they require the existence of certain template files.

public array requiredTemplates ( )
return array

List of code template files that are required. They should be file paths relative to \yii\gii\generators\controller\templatePath.

rules() public method

Child classes should override this method like the following so that the parent rules are included:

return array_merge(parent::rules(), [
    ...rules for the child class...
]);
public void rules ( )
stickyAttributes() public method

Returns the list of sticky attributes.

A sticky attribute will remember its value and will initialize the attribute with this value when the generator is restarted.

public array stickyAttributes ( )
return array

List of sticky attributes

successMessage() public method

Returns the message to be displayed when the newly generated code is saved successfully.

Child classes may override this method to customize the message.

public string successMessage ( )
return string

The message to be displayed when the newly generated code is saved successfully.