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 void __get ( $name ) | ||
$name |
public function __get($name)
{
return isset($this->_options[$name]) ? $this->_options[$name] : null;
}
public void __set ( $name, $value ) | ||
$name | ||
$value |
public function __set($name, $value)
{
$this->_options[$name] = $value;
}
public void actions ( ) |
public function actions()
{
$actions = [];
foreach ($this->generators as $name => $generator) {
$actions[$name] = [
'class' => 'yii\gii\console\GenerateAction',
'generator' => $generator,
];
}
return $actions;
}
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;
}
protected void formatHint ( $hint ) | ||
$hint |
protected function formatHint($hint)
{
$hint = preg_replace('%<code>(.*?)</code>%', '\1', $hint);
$hint = preg_replace('/\s+/', ' ', $hint);
return wordwrap($hint);
}
public void getActionArgsHelp ( $action ) | ||
$action |
public function getActionArgsHelp($action)
{
return [];
}
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));
}
public void getActionHelpSummary ( $action ) | ||
$action |
public function getActionHelpSummary($action)
{
if ($action instanceof InlineAction) {
return parent::getActionHelpSummary($action);
}
/** @var $action GenerateAction */
return $action->generator->getName();
}
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;
}
public void init ( ) |
public function init()
{
parent::init();
foreach ($this->generators as $id => $config) {
$this->generators[$id] = Instance::ensure(
$config,
Generator::className()
);
}
}
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)
);
}