Class yii\gii\console\GenerateController

Inheritanceyii\gii\console\GenerateController » yii\console\Controller
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-gii/blob/master/src/console/GenerateController.php

This is the command line version of Gii - a code generator.

You can use this command to generate models, controllers, etc. For example, to generate an ActiveRecord model based on a DB table, you can run:

$ ./yii gii/model --tableName=city --modelClass=City

Public Properties

Hide inherited properties

Property Type Description Defined By
$generators array A list of the available code generators yii\gii\console\GenerateController
$module yii\gii\Module yii\gii\console\GenerateController
$overwrite boolean Whether to overwrite all existing code files when in non-interactive mode. yii\gii\console\GenerateController

Protected Methods

Hide inherited methods

Method Description Defined By
formatHint() yii\gii\console\GenerateController

Property Details

Hide inherited properties

$generators public property

A list of the available code generators

public array $generators = []
$module public property
public yii\gii\Module $module null
$overwrite public property

Whether to overwrite all existing code files when in non-interactive mode. Defaults to false, meaning none of the existing code files will be overwritten. This option is used only when --interactive=0.

public boolean $overwrite false

Method Details

Hide inherited methods

__get() public method

public void __get ( $name )
$name

                public function __get($name)
{
    return isset($this->_options[$name]) ? $this->_options[$name] : null;
}

            
__set() public method

public void __set ( $name, $value )
$name
$value

                public function __set($name, $value)
{
    $this->_options[$name] = $value;
}

            
actionIndex() public method

public void actionIndex ( )

                public function actionIndex()
{
    $this->run('/help', ['gii']);
}

            
actions() public method

public void actions ( )

                public function actions()
{
    $actions = [];
    foreach ($this->generators as $name => $generator) {
        $actions[$name] = [
            'class' => 'yii\gii\console\GenerateAction',
            'generator' => $generator,
        ];
    }
    return $actions;
}

            
createAction() public method

public void createAction ( $id )
$id

                public function createAction($id)
{
    /** @var $action GenerateAction */
    $action = parent::createAction($id);
    foreach ($this->_options as $name => $value) {
        $action->generator->$name = $value;
    }
    return $action;
}

            
formatHint() protected method

protected void formatHint ( $hint )
$hint

                protected function formatHint($hint)
{
    $hint = preg_replace('%<code>(.*?)</code>%', '\1', $hint);
    $hint = preg_replace('/\s+/', ' ', $hint);
    return wordwrap($hint);
}

            
getActionArgsHelp() public method

public void getActionArgsHelp ( $action )
$action

                public function getActionArgsHelp($action)
{
    return [];
}

            
getActionHelp() public method

public void getActionHelp ( $action )
$action

                public function getActionHelp($action)
{
    if ($action instanceof InlineAction) {
        return parent::getActionHelp($action);
    }
    /** @var $action GenerateAction */
    $description = $action->generator->getDescription();
    return wordwrap(preg_replace('/\s+/', ' ', $description));
}

            
getActionHelpSummary() public method

public void getActionHelpSummary ( $action )
$action

                public function getActionHelpSummary($action)
{
    if ($action instanceof InlineAction) {
        return parent::getActionHelpSummary($action);
    }
    /** @var $action GenerateAction */
    return $action->generator->getName();
}

            
getActionOptionsHelp() public method

public void getActionOptionsHelp ( $action )
$action

                public function getActionOptionsHelp($action)
{
    if ($action instanceof InlineAction) {
        return parent::getActionOptionsHelp($action);
    }
    /** @var $action GenerateAction */
    $attributes = $action->generator->attributes;
    unset($attributes['templates']);
    $hints = $action->generator->hints();
    $options = parent::getActionOptionsHelp($action);
    foreach ($attributes as $name => $value) {
        $type = gettype($value);
        $options[$name] = [
            'type' => $type === 'NULL' ? 'string' : $type,
            'required' => $value === null && $action->generator->isAttributeRequired($name),
            'default' => $value,
            'comment' => isset($hints[$name]) ? $this->formatHint($hints[$name]) : '',
        ];
    }
    return $options;
}

            
getUniqueID() public method

public void getUniqueID ( )

                public function getUniqueID()
{
    return $this->id;
}

            
init() public method

public void init ( )

                public function init()
{
    parent::init();
    foreach ($this->generators as $id => $config) {
        $this->generators[$id] = Instance::ensure(
            $config,
            Generator::className()
        );
    }
}

            
options() public method

public void options ( $id )
$id

                public function options($id)
{
    $options = parent::options($id);
    $options[] = 'overwrite';
    if (!isset($this->generators[$id])) {
        return $options;
    }
    $attributes = $this->generators[$id]->attributes;
    unset($attributes['templates']);
    return array_merge(
        $options,
        array_keys($attributes)
    );
}