2011-05-02 29 views

回答

0

這裏沒有單一的命令。 您可以創建一個讀取schema.yml的任務,從那裏檢索所有模型名稱並調用doctrine:generate-module任務與每個模型名稱。

這裏是這樣的任務的一個例子:

class BuildAllModulesTask extends sfBaseTask 
{ 
    protected function configure() 
    { 
     $this->addOptions(
      array(
       new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'backend'), 
       new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'), 
       new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'), 
      ) 
     ); 

     $this->namespace = 'ns'; 
     $this->name = 'build-all-modules'; 
     $this->aliases = array('bam'); 

     $this->briefDescription = 'Builds a module for each model in schema.yml'; 
     $this->detailedDescription = <<<EOF 
The Task [Builds a module for each model in schema.yml|INFO] 
Call it with: 

    [php symfony ns:build-all-modules|INFO] 
EOF; 

     $this->addOptions(
      array(
       new sfCommandOption('app', null, sfCommandOption::PARAMETER_OPTIONAL, 'Application', 'backend') 
      ) 
     ); 

    } 

    /** 
    * 
    * 
    * @param array $arguments 
    * @param array $options 
    * @return void 
    */ 
    protected function execute($arguments = array(), $options = array()) 
    { 
     $this->logSection('Step 1', 'Read all models from schema.yml'); 

     $yaml = new sfYamlParser(); 
     $models_array = $yaml->parse(file_get_contents(sfConfig::get('sf_config_dir') . '/doctrine/schema.yml')); 
     $this->logSection('Step 1', 'There are ' . sizeof($models_array) . ' models in the schema.yml'); 

     $this->logSection('STEP 2', 'Go through all models from schema.yml and build an admin module in the "' . $options['app'] . '"'); 


     $sfDoctrineGenerateAdminTask = new sfDoctrineGenerateAdminTask($this->dispatcher, $this->formatter); 

     $generate_options = array(
      'theme' => 'admin', // You can use here some other theme like jroller from ThemeJRoller plugin 
      'env' => 'prod' // Here you can change to dev to see verbose output 
     ); 

     foreach ($models_array as $model_name => $model_data) { 
      if ($model_name == 'options') continue; 

      $this->logSection('STEP 2', 'Processing "' . $model_name . '"'); 

      $args = array(
       'application' => $options['app'], 
       'route_or_model' => $model_name, 
      ); 
      $sfDoctrineGenerateAdminTask->run($args, $generate_options); 

     } 
    } 
} 
+0

這項任務可以創建的所有後端模塊? – JohnnyeM 2011-05-03 07:57:34

+0

是的,我添加了任務示例,請看看 – 2011-05-06 06:26:17

相關問題