我试图通过创建覆盖SymfonyGeneratorBundle模板
\app\Resources\SensioGeneratorBundle\skeleton\crud\views\index.html.twig
Run Code Online (Sandbox Code Playgroud)
该文件应替换:
\vendor\bundles\Sensio\Bundle\GeneratorBundle\Resources\skeleton\crud\views\index.html.twig
Run Code Online (Sandbox Code Playgroud)
但它仍然使用原始文件甚至在cache:clear.如何做到这一点之后没有创建新的包就像不能覆盖Symfony2 GeneratorBundle中的标准骨架视图?
Mun*_*Das 14
注册您的包后立即SensioGeneratorBundle在app/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();
Run Code Online (Sandbox Code Playgroud)
然后在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);
}
Run Code Online (Sandbox Code Playgroud)
您必须将skeleton文件夹复制到YourBundle\Resource并修改模板.
cba*_*lar 12
要覆盖编辑模板,例如,在2.3+版本中,复制文件:
vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud/views/edit.html.twig.twig
Run Code Online (Sandbox Code Playgroud)
对于目录:
app/Resources/SensioGeneratorBundle/skeleton/crud/views/edit.html.twig.twig
Run Code Online (Sandbox Code Playgroud)
现在,只需使用默认命令生成crud,它将使用新模板.