Class yii\gii\console\GenerateController
| Inheritance | yii\gii\console\GenerateController » yii\console\Controller |
|---|---|
| Available since extension's version | 2.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
| 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 |
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| formatHint() | yii\gii\console\GenerateController |
Property Details
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.
Method Details
| public __get ( mixed $name ) | ||
| $name | mixed | |
public function __get($name)
{
return isset($this->_options[$name]) ? $this->_options[$name] : null;
}
| public __set ( mixed $name, mixed $value ) | ||
| $name | mixed | |
| $value | mixed | |
public function __set($name, $value)
{
$this->_options[$name] = $value;
}
| public actions ( ) |
public function actions()
{
$actions = [];
foreach ($this->generators as $name => $generator) {
$actions[$name] = [
'class' => 'yii\gii\console\GenerateAction',
'generator' => $generator,
];
}
return $actions;
}
| public createAction ( mixed $id ) | ||
| $id | mixed | |
public function createAction($id)
{
/** @var $action GenerateAction */
$action = parent::createAction($id);
foreach ($this->_options as $name => $value) {
$action->generator->$name = $value;
}
return $action;
}
| protected mixed formatHint ( mixed $hint ) | ||
| $hint | mixed | |
protected function formatHint($hint)
{
$hint = preg_replace('%<code>(.*?)</code>%', '\1', $hint);
$hint = preg_replace('/\s+/', ' ', $hint);
return wordwrap($hint);
}
| public getActionArgsHelp ( mixed $action ) | ||
| $action | mixed | |
public function getActionArgsHelp($action)
{
return [];
}
| public getActionHelp ( mixed $action ) | ||
| $action | mixed | |
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));
}
| public getActionHelpSummary ( mixed $action ) | ||
| $action | mixed | |
public function getActionHelpSummary($action)
{
if ($action instanceof InlineAction) {
return parent::getActionHelpSummary($action);
}
/** @var $action GenerateAction */
return $action->generator->getName();
}
| public getActionOptionsHelp ( mixed $action ) | ||
| $action | mixed | |
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;
}
| public init ( ) |
public function init()
{
parent::init();
foreach ($this->generators as $id => $config) {
$this->generators[$id] = Instance::ensure(
$config,
Generator::className()
);
}
}
| public options ( mixed $id ) | ||
| $id | mixed | |
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)
);
}