7

我正在尝试通过创建来覆盖 SymfonyGeneratorBundle 模板

\app\Resources\SensioGeneratorBundle\skeleton\crud\views\index.html.twig

该文件应替换:

\vendor\bundles\Sensio\Bundle\GeneratorBundle\Resources\skeleton\crud\views\index.html.twig

但它仍然使用原始文件,即使在cache:clear.How to do that w/o create new bundle like Can't override the standard skeleton views in Symfony2 GeneratorBundle

4

3 回答 3

14

SensioGeneratorBundleapp/AppKernel.php例如以下之后立即注册您的捆绑包:

// app/AppKernel.php

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
    //.....
    $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
    $bundles[] = new Namespace\YourBundle();
}

// Or outside if, should you want your bundle to be available in production environment
$bundles[] = new Namespace\YourBundle();

然后在YourBundle.php 覆盖registerCommands方法中,

// Bundle\YourBundle.php

// other declarations
use Symfony\Component\Console\Application;
use Sensio\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator;
use Symfony\Component\Filesystem\Filesystem;


public function registerCommands(Application $application){
    $crudCommand = $application->get('generate:doctrine:crud');
    $generator = new DoctrineCrudGenerator(new FileSystem, __DIR__.'/Resources/skeleton/crud');
    $crudCommand->setGenerator($generator);

    parent::registerCommands($application);
}

您必须将skeleton文件夹复制到YourBundle\Resource并修改模板。

于 2012-04-21T19:58:26.417 回答
12

要覆盖编辑模板,例如,在 2.3+ 版本中,复制文件:

vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud/views/edit.html.twig.twig

对于目录:

app/Resources/SensioGeneratorBundle/skeleton/crud/views/edit.html.twig.twig

现在,只需使用默认命令生成 crud,它将使用新模板。

于 2013-09-05T14:47:47.603 回答
0

m2mdas 的答案对我有用,但只有在发现它应该阅读之后

文件系统而不是文件系统!

查看您的vendors/symfony/.../Filesystem 文件夹以验证这一点。

于 2013-06-19T11:48:30.787 回答