/** * Generate Giiant Model and Giiant CRUD using physical table * @param integer $id * @throws HttpException */ public function actionGenerate($id) { $table = $this->findModel($id); $setting = Setting::find()->where(["id" => 1])->one(); //Generate Model $params = ['interactive' => false, 'overwrite' => true, 'template' => "default", 'ns' => $setting->model_namespace, 'db' => "db", 'tableName' => $table->slug_name, 'tablePrefix' => "", 'enableI18N' => false, 'singularEntities' => true, 'messageCategory' => "app", 'generateModelClass' => false, 'baseClassSuffix' => "", 'modelClass' => Inflector::camelize($table->slug_name), 'baseClass' => "yii\\db\\ActiveRecord", 'baseTraits' => null, 'tableNameMap' => [], 'generateQuery' => false, 'queryNs' => 'app\\models\\query', 'queryBaseClass' => 'yii\\db\\ActiveQuery']; $route = 'gii/giiant-model'; $app = \Yii::$app; $config = $GLOBALS['config']; unset($config["components"]["errorHandler"]); unset($config["components"]["user"]); $temp = new \yii\console\Application($config); $temp->runAction(ltrim($route, '/'), $params); unset($temp); \Yii::$app = $app; $table->model_class = $setting->model_namespace . "\\" . Inflector::camelize($table->slug_name); $table->model_base_class = $setting->model_namespace . "\\base\\" . Inflector::camelize($table->slug_name); $table->save(); //Generate CRUD $this->createDirectoryFromNamespace($setting->controller_namespace); $this->createDirectoryFromNamespace($setting->model_namespace . "\\search"); $name = Inflector::camelize($table->slug_name); $params = ['interactive' => false, 'overwrite' => true, 'template' => "default", 'modelClass' => $setting->model_namespace . '\\' . $name, 'searchModelClass' => $setting->model_namespace . '\\search\\' . $name, 'controllerNs' => $setting->controller_namespace, 'controllerClass' => $setting->controller_namespace . '\\' . $name . 'Controller', 'viewPath' => $setting->view_path, 'pathPrefix' => "", 'tablePrefix' => "", 'enableI18N' => false, 'singularEntities' => true, 'messageCategory' => "app", 'actionButtonClass' => "yii\\grid\\ActionColumn", 'baseControllerClass' => "yii\\web\\Controller", 'providerList' => [], 'skipRelations' => [], 'accessFilter' => true, 'tidyOutput' => true]; $route = 'gii/giiant-crud'; $app = \Yii::$app; $temp = new \yii\console\Application($config); $temp->runAction(ltrim($route, '/'), $params); unset($temp); \Yii::$app = $app; \Yii::$app->log->logger->flush(true); $table->controller_class = $setting->controller_namespace . '\\' . $name . 'Controller'; $table->view_path = $setting->view_path . "/" . Util::slugify($table->slug_name); $table->save(); \Yii::$app->session->addFlash("success", "Generate Success."); $this->redirect(["table/index"]); }