2

I use ./yiic webapp /path/to/name create a project, but I don't need some file that created.

Actual: assets css images index.php index-test.php protected themes

Expected: index.php protected

Where is template that I should to change.

4

1 回答 1

3

如果您希望真正改变这一点,您应该扩展(或修改)作为框架一部分的类 WebAppCommand。它可以在

Yii
-> Framework 
   ->cli
     -> commands
       ->WebAppCommand.php 

我建议您编写一个扩展WebAppCommand类的自定义类,而不是修改现有代码,只需删除调用 run 方法的单独方法中的目录,WebAppCommand并添加额外的行以删除不必要的目录。也许像这样的东西......

<?php 
 class MyCustomWebAppCommand extends WebAppCommand {
      private $_rootPath; // Need to redefine  and compute this as thevariable is defined as private in the parent class and better not touch core classes;
      public function run($args){
          parent::run($args);
          $path=strtr($args[0],'/\\',DIRECTORY_SEPARATOR);
          if(strpos($path,DIRECTORY_SEPARATOR)===false)
          $path='.'.DIRECTORY_SEPARATOR.$path;
          if(basename($path)=='..')
          $path.=DIRECTORY_SEPARATOR.'.';
          $dir=rtrim(realpath(dirname($path)),'\\/');
          if($dir===false || !is_dir($dir))
              $this->usageError("The directory '$path' is not valid. Please make sure the parent directory exists.");
          if(basename($path)==='.')
              $this->_rootPath=$path=$dir;
          else
              $this->_rootPath=$path=$dir.DIRECTORY_SEPARATOR.basename($path);
              $this->deleteDir($this->_rootPath.DIRECTORY_SEPARATOR."assets");
              $this->deleteDir($this->_rootPath.DIRECTORY_SEPARATOR."themes");
              $this->deleteDir($this->_rootPath.DIRECTORY_SEPARATOR."images");
              $this->deleteDir($this->_rootPath.DIRECTORY_SEPARATOR."css");
              unset($this->_rootPath.DIRECTORY_SEPARATOR."index-test.php");
      }


       public static function deleteDir($dirPath) {
          if (! is_dir($dirPath)) {
            throw new InvalidArgumentException("$dirPath must be a directory");
          }
          if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
             $dirPath .= '/';
          }
          $files = glob($dirPath . '*', GLOB_MARK);
          foreach ($files as $file) {
            if (is_dir($file)) {
               self::deleteDir($file);
             } else {
               unlink($file);
             }
         }
         rmdir($dirPath);
         }
}

最后调用 MyCustomWebApp 而不是调用 WebApp。

PS我通常建议不要在不知道自己在做什么的情况下扩展/修改核心类,它会在您无法预料的地方破坏很多东西,并且升级变得非常困难。在您的情况下更简单的是手动删除文件。

于 2013-10-19T16:05:14.070 回答