Beispiel #1
0
 /**
  * @param $model
  */
 private function makeCrud($model)
 {
     $generator = new \yii\gii\generators\crud\Generator();
     $generator->enableI18N = TRUE;
     $generator->modelClass = AppFile::useForwardSlash($this->models_path . chr(92) . $model);
     $generator->searchModelClass = AppFile::useForwardSlash($this->models_search_path . chr(92) . $model);
     $generator->controllerClass = AppFile::useForwardSlash($this->controller_path . chr(92) . $model . 'Controller');
     if ($this->crud_template != 'default') {
         $generator->templates[$this->crud_template] = Yii::getAlias($this->crud_template_path);
         $generator->template = $this->crud_template;
     } else {
         $generator->template = 'default';
     }
     $files = $generator->generate();
     foreach ($files as $file) {
         $file->path = AppFile::useBackslash($file->path);
         $dir = AppFile::removeFileInPath($file->path);
         AppFile::buildPath($dir);
         $content = $file->content;
         if (strpos($file->path, '/views/') != FALSE) {
             $dir_name = trim(preg_replace('/([A-Z])/', " \$1", $model));
             $dir_name = strtolower(str_replace(' ', '-', $dir_name));
             $path = AppFile::useBackslash(Yii::getAlias('@' . $this->controller_path)) . '/' . $dir_name;
             $file->path = AppFile::fileFromPath($file->path);
             $path = preg_replace('/\\/controllers\\//', '/views/', $path);
             AppFile::buildPath($path);
             $file->path = $path . '/' . $file->path;
         }
         AppFile::writeFile($file->path, $content);
     }
 }