无法覆盖 Symfony2 GeneratorBundle 中的标准骨架视图

发布于 2024-12-02 00:38:05 字数 266 浏览 1 评论 0原文

我无法覆盖 GeneratorBundle 的骨架视图。

我首先尝试在 /app/Resources/SensioGeneratorBundle/sculpt/crud/views/index.html.twig 中添加我的视图,

但它不起作用,所以我尝试创建一个扩展 SensioGeneratorBundle 的新捆绑包,并将我的视图复制到其中资源文件夹。

我已经设法使用树枝形式的主题,但我需要个性化由doctrine:generate:crud 命令生成的视图。

I don't manage to override the skeleton views of the generatorBundle.

I've first tried by adding my view in /app/Resources/SensioGeneratorBundle/skeleton/crud/views/index.html.twig

It didn't worked so I tried to create a new Bundle extending SensioGeneratorBundle and copy the my view in its Resources folder.

I already manage to use themes for twig forms, but I need to personalize the views generated by the doctrine:generate:crud command.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清眉祭 2024-12-09 00:38:05

首先:相应的骨架视图位于此处:

vendor/bundles/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud

快速而肮脏,您应该可以通过覆盖这些视图文件来解决问题 - 但这不是我们想要的;)

在:

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 中并在构造函数中设置不同的 $sculptureDir

编辑:

在我的测试环境中如何实现它的快速示例(我只做了一个快速测试;):

为自定义生成器生成一个新的包:php app/consolegenerate:bundle< /code> 并按照说明进行操作。不需要路线。我为此示例选择:Acme/CrudGeneratorBundle(或使用现有的包)

在新创建的包目录中创建一个名为“Command”的文件夹。

将命令类放置在此文件夹中。

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

将vendor/bundles/Sensio/Bundle/GeneratorBundle/Resources/sculpture/crud复制到您的资源中(在我的示例中为“src/Acme/CrudGeneratorBundle/Resources/crud”)

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

In:

vendor/bundles/Sensio/Bundle/GeneratorBundle/Command/GenerateDoctrineCrudCommand.php

there is an accessor for the Generator:

protected function getGenerator()
{
    if (null === $this->generator) {
        $this->generator = new DoctrineCrudGenerator($this->getContainer()->get('filesystem'), __DIR__.'/../Resources/skeleton/crud');
    }

    return $this->generator;
} 

One can try to override this method in your extending Bundle and set a different $skeletonDir in the constructor.

Edit:

Quick example in my test environment how it can be achieved (I only made a quick test ;):

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)

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

Copy the vendor/bundles/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud to your Resources (in my example "src/Acme/CrudGeneratorBundle/Resources/crud")

动次打次papapa 2024-12-09 00:38:05

这对我来说是最好的解决方案:
symfony2-how-to-override-core-template

不添加命令,但会修改该特定包的骨架。

This was the best solution for me:
symfony2-how-to-override-core-template

doesn't add a command but modifies the skeleton for that particular bundle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文