Skip to content

Instantly share code, notes, and snippets.

@mdmunir
Created May 28, 2021 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdmunir/bd98f2cf440354304446ddf1c2fa947c to your computer and use it in GitHub Desktop.
Save mdmunir/bd98f2cf440354304446ddf1c2fa947c to your computer and use it in GitHub Desktop.
artisan gii generator model
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class GiiModel extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'gii:model {--tableName=} {--modelClass=} {--ns=App\Models} {--baseClass=yii\db\ActiveRecord}
{--generateQuery} {--queryClass=} {--queryNs=App\Models} {--queryBaseClass=yii\db\ActiveQuery}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Model Generator';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$controller = new \yii\gii\console\GenerateController('gii', \Yii::$app, [
'generators' => [
'model' => ['class' => 'yii\gii\generators\model\Generator'],
],
]);
$options = [
'tableName' => $this->option('tableName'),
'modelClass' => $this->option('modelClass'),
'ns' => $this->option('ns'),
'baseClass' => $this->option('baseClass'),
'generateQuery' => $this->option('generateQuery'),
'queryClass' => $this->option('queryClass'),
'queryBaseClass' => $this->option('queryBaseClass'),
'queryNs' => $this->option('queryNs'),
];
\Yii::configure($controller, $options);
$controller->run('model', []);
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment