无法覆盖Symfony2 GeneratorBundle中的标准骨架视图 [英] Can't override the standard skeleton views in Symfony2 GeneratorBundle
问题描述
我无法覆盖generatorBundle的骨架视图。
I don't manage to override the skeleton views of the generatorBundle.
我首先尝试在/ app / Resources / SensioGeneratorBundle / skeleton中添加视图/crud/views/index.html.twig
I've first tried by adding my view in /app/Resources/SensioGeneratorBundle/skeleton/crud/views/index.html.twig
它没有用,所以我尝试创建一个扩展SensioGeneratorBundle的新Bundle并将其视图复制到其Resources文件夹中。
It didn't worked so I tried to create a new Bundle extending SensioGeneratorBundle and copy the my view in its Resources folder.
我已经可以在树枝样式中使用主题,但是我需要个性化由doctrine:generate:crud命令生成的视图。
I already manage to use themes for twig forms, but I need to personalize the views generated by the doctrine:generate:crud command.
推荐答案
首先:相应的骨架视图位于此处:
First of all: The corresponding skeleton views are located here:
vendor/bundles/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud
又脏又臭您应该通过覆盖这些视图文件来解决问题-但这不是我们想要的;)
Quick and dirty you should be fine by overriding these view files - but thats not what we want ;)
在:
vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineCrudCommand.php
生成器有一个访问器:
protected function getGenerator()
{
if (null === $this->generator) {
$this->generator = new DoctrineCrudGenerator($this->getContainer()->get('filesystem'), __DIR__.'/../Resources/skeleton/crud');
}
return $this->generator;
}
一个人可以尝试在扩展的Bundle中覆盖此方法并设置其他 $ skeletonDir
。
One can try to override this method in your extending Bundle and set a different $skeletonDir
in the constructor.
编辑:
在我的测试环境中如何实现的快速示例(我只是进行了快速测试;):
Quick example in my test environment how it can be achieved (I only made a quick test ;):
为自定义生成新的包生成器: php应用程序/控制台generate:bundle
并按照说明进行操作。不需要路线。我为该示例选择了该示例:Acme / CrudGeneratorBundle(或使用现有的包)
Generate a new bundle for the custom generator: php app/console generate:bundle
and follow the instructions. A route is not needed. I chose for this example: Acme/CrudGeneratorBundle (Or use an existing bundle)
在新创建的包目录中创建一个名为 Command的文件夹。
Create a folder called "Command" in the newly created bundle directory.
在此文件夹中放置命令类。
Place a command class in this folder.
<?php
//src/Acme/CrudGeneratorBundle/Command/MyDoctrineCrudCommand.php
namespace Acme\CrudGeneratorBundle\Command;
use Sensio\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator;
class MyDoctrineCrudCommand extends \Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand
{
protected function configure()
{
parent::configure();
$this->setName('mydoctrine:generate:crud');
}
protected function getGenerator()
{
$generator = new DoctrineCrudGenerator($this->getContainer()->get('filesystem'), __DIR__.'/../Resources/skeleton/crud');
$this->setGenerator($generator);
return parent::getGenerator();
}
}
复制供应商/捆绑/ Sensio /捆绑/ GeneratorBundle / Resources / skeleton / crud到您的资源(在我的示例中为 src / Acme / CrudGeneratorBundle / Resources / crud)
Copy the vendor/bundles/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud to your Resources (in my example "src/Acme/CrudGeneratorBundle/Resources/crud")
这篇关于无法覆盖Symfony2 GeneratorBundle中的标准骨架视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!