2

プロジェクトの作成を使用./yiic webapp /path/to/nameしますが、作成されたファイルは必要ありません。

実際: assets css images index.php index-test.php protected themes

期待される: index.php protected

変更する必要があるテンプレートはどこですか。

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);
         }
}

最後に、WebApp を呼び出す代わりに MyCustomWebApp を呼び出します。

PS 一般に、自分が何をしているのかを知らずにコア クラスを拡張/変更しないことをお勧めします。予期しない場所で多くのことが壊れ、アップグレードが非常に困難になります。あなたの場合、ファイルを手動で削除する方が簡単です。

于 2013-10-19T16:05:14.070 に答える