天道酬勤,学无止境

Can't override the standard skeleton views in Symfony2 GeneratorBundle

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.

评论

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

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.

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Symfony2:如何覆盖核心模板?(Symfony2: how to override core template?)
    问题 我试图通过创建来覆盖 SymfonyGeneratorBundle 模板 \app\Resources\SensioGeneratorBundle\skeleton\crud\views\index.html.twig 该文件应替换: \vendor\bundles\Sensio\Bundle\GeneratorBundle\Resources\skeleton\crud\views\index.html.twig 但即使在cache:clear.之后它仍然使用原始文件cache:clear. 如何在不创建新包的情况下做到这一点,例如无法覆盖 Symfony2 GeneratorBundle 中的标准骨架视图? 回答1 在app/AppKernel.php之后SensioGeneratorBundle注册您的包,例如: // 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
  • Symfony2: how to override core template?
    I am trying to override SymfonyGeneratorBundle templates by creating \app\Resources\SensioGeneratorBundle\skeleton\crud\views\index.html.twig That file should replace: \vendor\bundles\Sensio\Bundle\GeneratorBundle\Resources\skeleton\crud\views\index.html.twig But it still uses original file even after cache:clear. How to do that w/o creating new bundle like Can't override the standard skeleton views in Symfony2 GeneratorBundle?
  • 有没有办法在 symfony2 中自动更新 AppKernel?(Is there a way to update automatically the AppKernel in symfony2?)
    问题 可能类似于 generate:bundle 命令(在生成包后提示更新 AppKernel)或 Composer(使用您安装的依赖项更新您的自动加载)。 我想获得与 generate:bundle 类似的功能,但我想添加一个我刚下载的包而不是创建一个新的包,而不必手动编辑 AppKernel。 回答1 我找不到扩展现有命令的方法,所以我的想法是在现有包中创建一个新的控制台命令。 namespace Your\OriginalBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class AppendNewBundleCommand extends
  • Is there a standard skeleton, or instructions, for setting up an open-sourced Symfony2 bundle complete with travis-ci and composer? [closed]
    This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 8 years ago. If there are, then they must be very well hidden...I've tried googling, traversing the maze of Symfony docs, asking on twitter and searching here but have found nothing useful. Stumbling block 1: Where to create my bundle, designed to be open-sourced? If I
  • 如何在 Symfony2 项目的 prod 环境中启用调试工具栏?(How enable debugging toolbar in prod environment of a Symfony2 project?)
    问题 我有一个现有的项目,只是想知道哪些文件以及我应该更改哪些内容以使 prod 环境中的调试工具栏可见 回答1 您应该在AppKernel.php文件中进行更改,以便在 prod 环境中也启用包,并将路由从routing_dev.yml更改为routing.yml包定义路由。 然后也在config.yml添加配置。 例如: 应用内核.php // Move this outside the if statement $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); if (in_array($this->getEnvironment(), array('dev', 'test'), true)) { $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); } 路由.yml #add this _wdt: resource: "
  • FOSJsRoutingBundle installation on Symfony2
    I have tried to install FOSJsRoutingBundle through reading this tutorial on this link: https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Resources/doc/index.md but whenever I run this command $ php app/console assets:install --symlink web the following list of errors messages is displayed: PHP Fatal error: Class 'FOS\JsRoutingBundle\FOSJsRoutingBundle' not found in C:\wamp\www\calendar\app\AppKernel.php on line 19 PHP Stack trace: PHP 1. {main}() C:\wamp\www\calendar\app\console:0 PHP 2. Symfony\Component\Console\Application->run() C:\wamp\www\calendar\app\console:27 PHP 3
  • Symfony2 上的 FOSJsRoutingBundle 安装(FOSJsRoutingBundle installation on Symfony2)
    问题 我试图通过阅读此链接上的本教程来安装 FOSJsRoutingBundle:https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/blob/master/Resources/doc/index.md 但每当我运行此命令时 $ php app/console assets:install --symlink web 将显示以下错误消息列表: PHP 致命错误:在第 19 行的 C:\wamp\www\calendar\app\AppKernel.php 中找不到 Class 'FOS\JsRoutingBundle\FOSJsRoutingBundle' PHP 堆栈跟踪: PHP 1. {main}() C:\wamp\www\calendar\app\console:0 PHP 2. Symfony\Component\Console\Application->run() C:\wamp\www\calendar\app\console:27 PHP 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() C:\wamp\www\calendar\vendor\symfony\symfony\src\Symfony\Component\Console
  • Symfony2 错误:找不到命名的映射文件(Symfony2 Error: No mapping file found named)
    问题 我正在使用 Symfony2,当我尝试生成模式($ php app/console 原则:generate:schema)时,出现错误.. [Doctrine\ORM\Mapping\MappingException] No mapping file found named 'xxx.UserBundle.Entity.User.php' for class 'xxx\UserBundle\Entity\User'. 我在项目中只有 2 个捆绑包: 用户包文件包 我使用以下代码将 FileBundle 与 UserBundle 连接起来: /** * @ORM\ManyToOne(targetEntity="xxx\UserBundle\Entity\User") **/ protected $user; 文件的标题是这样的: namespace xx\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity **/ class User { ###...###} FileBundle 非常相似..谢谢! 回答1 您正在混合 Doctrine 映射格式,您在 Resources/config/doctrine 中有注释和至少一个 XML 文件 从 symfony 文档: "A bundle
  • Symfony2 - 覆盖模板包(Symfony2 - override template bundle)
    问题 我想覆盖默认的 SonataAdmin 模板。 我在我的 Namespace/bundle/resources/views(相同的结构,相同的文件名,相同的内容)中创建了一个 standard_layout.html.twig 我在目标模板中复制了源模板的所有内容,我只是对目标的某些部分进行了编辑....什么也没有 谢谢你的帮助再见 回答1 您有捆绑继承 http://symfony.com/doc/current/cookbook/bundles/inheritance.html 的解决方案,它不仅可以覆盖模板,还可以覆盖方法。 或者你有 http://symfony.com/doc/2.0/book/templating.html#overriding-bundle-templates 只关注模板。 最后,您可以尝试创建: app/Resources/SonataAdminBundle/views/CRUD/base_show_field.html.twig
  • 在 symfony2.6 和 FOSUserBundle 1.3 中不覆盖模板有什么问题(What is the issue with not overriding templates in symfony2.6 and FOSUserBundle 1.3)
    问题 我正在尝试使用“简单”选项覆盖 FOSUserBundle 的基本布局,将克隆路径设为.app/Resources/FOSUserBundle/views/layout.html.twig ,但 symfony2.6 继续从内部渲染模板供应商目录。 我的作曲家要求: "require": { "php": ">=5.3.3", "symfony/symfony": "2.6.*", "doctrine/orm": "~2.2,>=2.2.3,<2.5", "doctrine/dbal": "<2.5", "doctrine/doctrine-bundle": "~1.2", "twig/extensions": "~1.0", "symfony/assetic-bundle": "~2.3", "symfony/swiftmailer-bundle": "~2.3", "symfony/monolog-bundle": "~2.4", "sensio/distribution-bundle": "~3.0,>=3.0.12", "sensio/framework-extra-bundle": "~3.0,>=3.0.2", "incenteev/composer-parameter-handler": "~2.0", "friendsofsymfony/user-bundle
  • 没有扩展能够加载“ facebookbundle” symfony2的配置(There is no extension able to load the configuration for “facebookbundle” symfony2)
    问题 我创建了自己的FacebookBundle, 我收到此错误: 没有扩展能够加载“ facebookbundle”的配置(在/facebookx/app/config/config_dev.yml中)。 查找名称空间“ facebookbundle”,找到“框架”,“安全性”,“树枝”,“独白”,“ swiftmailer”,“资产”,“学说”,“ sensio_framework_extra”,“ jms_aop”,“ jms_di_extra”,“ jms_security_extra” “,” d_facebook“,” d_user“,” d_security“,” web_profiler“,” sensio_distribution“ 该错误消息表示我在config.yml中获得了“ facebookbundle”条目,该条目未被任何扩展名使用? 我的config.yml facebookbundle: file: %kernel.root_dir%/../src/FacebookBundle/Facebook/FacebookInit.php alias: facebook app_id: xxx secret: xxx cookie: true permissions: [email, user_birthday, user_location, user
  • Symfony2 fos登录,注册和忘记密码在一个视图中(Symfony2 fos login, register and forgot password in one view)
    问题 我需要将购买的模板应用到我们的仪表板。 在这个模板中,登录、注册和忘记密码表单都在同一个视图下,并使用简单的 JQuery 在它们之间切换。 我一直在寻找一种将所有三种形式合二为一的不错的、不太浮夸的方式,但我一无所获。 我的常备选项(如我所见),以及为什么我不喜欢其中任何一个: 从 fos 包中获取视图,将它们复制到/app/Resources/FOSUserBundle/views/ ,删除{% extend %}部分并在我自己的登录视图中{% include %}它们。 不喜欢的原因:对我来说,这看起来有点像一个快速n-dirty修复 - “那部分不起作用?让我们把它断开!” :) 扩展 fos 包,在LoginAction和RegisterAction接受一个额外的参数,在我自己的登录视图中使用{% render %}和参数。 不喜欢的原因:扩展整个包并修改两个不同的控制器只是为了改变它的呈现方式感觉就像糟糕的 MVC。 XHR 加载所有内容。 不喜欢的原因:这种方法在使用内页时是有意义的,但对于无论如何都要重新加载的页面,它就没有意义了。 TL;DR 版本:我正在寻找一种在一个页面中包含登录、注册和忘记密码表单的非黑客方式。 任何帮助将不胜感激! 回答1 我找到了一个适合我当前项目的解决方案。 预先提出的解决方案的优点和缺点: 好处: 很少的 LOC 可以实施
  • Laravel Forge Deployment environment variable issue
    My App will not deploy because it is missing required environment variables. When I set these from within Forge, they appear. As soon as I hit deploy they all disappear, then my deploy fails. I am using Symfony2 with Digital Ocean - but shouldn't make a difference, the issue is all environment variables get deleted prior to a deploy. That can't be right? Here is the error message from Symfony, but it is due to the environment variable not being set (in forge I can see it get deleted right before a deploy) - Installing tedivm/stash-bundle (v0.4.2) Loading from cache - Installing twig/extensions
  • Symfony2 - override template bundle
    I want to override the default SonataAdmin Template. I create a standard_layout.html.twig in my Namespace/bundle/resources/views (same structur, same file name, same content) I copied all the content of the source template in my target template, i just edit some part of the target off course....and nothing thanks for your help Bye
  • Laravel Forge 部署环境变量问题(Laravel Forge Deployment environment variable issue)
    问题 我的应用程序将无法部署,因为它缺少必需的环境变量。 当我在 Forge 中设置这些时,它们就会出现。 一旦我点击部署它们都消失了,那么我的部署就会失败。 我正在将 Symfony2 与 Digital Ocean 一起使用 - 但应该没什么区别,问题是在部署之前所有环境变量都被删除了。 不可能吧? 这是来自 Symfony 的错误消息,但这是由于未设置环境变量(在伪造中我可以看到它在部署之前被删除) - Installing tedivm/stash-bundle (v0.4.2) Loading from cache - Installing twig/extensions (v1.2.0) Loading from cache Generating autoload files Creating the "app/config/parameters.yml" file PHP Fatal error: Class 'Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle' not found in /home/forge/beta.dashboardhub.io/app/AppKernel.php on line 31 PHP Stack trace: PHP 1. {main}() /home/forge/beta
  • Symfony2 如何检测从哪里加载模板?(How does Symfony2 detect where to load templates from?)
    问题 Symfony2 在哪里检测从哪里加载模板:来自app/Resourses/views/或来自Bundle/Resourses/views/ ? 在查看app/Resourses/views/之前,我需要覆盖它以在另一个目录中查找模板。 我找到了: Symfony\Bundle\FrameworkBundle\CacheWarmer\TemplateFinder 现在我只需要覆盖它。 如何? 回答1 Symfony2 使用此工作流程 访问路由,将控制权传递给控制器​​,渲染视图(模板) 如果视图未被覆盖( app/..../ ),则渲染包模板如果有覆盖,然后拿走它 所以问题是:如何覆盖模板? 在 symfony2 中覆盖模板有两种不同的方式 在app/resources目录中定义一个同名的模板。 一起“同名”你必须重现包的相同结构。 因此,如果您的模板在,即myFooBundle/views/mainTemplate.html.twig您必须通过在app/resources/myFooBundle/views创建一个新模板来覆盖它,并将其命名为mainTemplate.html.twig 您必须从头开始创建一个新包并覆盖getParent()方法,该方法必须返回一个包含要覆盖的包名称的字符串 ( myfooBundle )。 现在,如果您在原始模板的相同位置创建一个新模板
  • is it bad practice to kill a script inside of a function?
    I'm referring to using the die() function for something else than debugging. This is a "well it works" situation, but is it bad practice? use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Exception\IOExceptionInterface; /** * This Command will help Cjw create a new demo site to start off * with the Multisite bundle. * * Class CreateSiteCommand * @package Cjw\GeneratorBundle\Command */ class RemoveSiteCommand extends ContainerAwareCommand { private $vendor; //eg "Cjw" private $fullBundleName; //eg "SiteCjwNetworkBundle" private $fullBundleNameWithVendor; //eg
  • Service sensio_distribution.webconfigurator no found
    I work on a Symfony2.4 project and I decided to go into production environment but when emptying the cache production I got this error : [Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException] You have requested a non-existent service "sensio_distribution.webconfigurator". I don't know when this service is used but I searched the file "webconfigurator.xml" and I have found the service called "sensio_distribution.webconfigurator"... The file path is the following : vendor/sensio/Bundle/DIstributionBundle/Resources/config/webconfigurator.xml And this is the file : <?xml
  • Symfony2:如何结合 Twig 模板继承正确包含资产?(Symfony2: How to properly include assets in conjunction with Twig template inheritance?)
    问题 我目前正在使用 Symfony 2.1.0 开发 Web 应用程序。 我已经通读了本书的模板一章,我正在尝试在我的网页中包含资产(现在,它只是一个单独的样式表)。 我使用的是书中提到的三级继承系统,目前我的应用结构是这样的: 应用程序/资源/视图/ base.html.twig:基本模板,包含标题、样式表和正文块。 src/My/PageBundle/Resources/views layout.html.twig:布局模板(扩展基础模板),将主样式表附加到样式表块,并覆盖主体块,包括navigation.html.twig并定义一个内容块 layout-admin.html.twig:与上面相同,但包括navigation-admin.html.twig src/My/PageBundle/Resources/views/Main 标准模板,扩展布局模板并覆盖其内容块 src/My/PageBundle/Resources/views/Administration 管理模板。 与上面相同,但扩展了管理布局模板。 src/My/PageBundle/Resources/public/css main.css:主样式表 如您所见,我已将样式表放入我的包中。 我不知道这是否是好的做法。 现在,事情是,在 layout.html 我添加了这个: {% block
  • yaml / symfony2:覆盖配置(yaml/symfony2: Override configurations)
    问题 我想在我的 config_test.yml 中覆盖 config_dev.yml 中的一些配置。 因此,想象一下 config_dev.yml 中的以下部分: monolog: handlers: main: type: stream path: %kernel.logs_dir%/%kernel.environment%.log level: debug firephp: type: firephp level: info 在我的测试环境中,我根本不需要记录器。 所以我试过了 monolog: ~ 没有效果。 我也试过: monolog: handlers: main: ~ firephp: ~ 再次没有任何影响。 然后我测试 monolog: handlers: main: type: ~ path: ~ level: ~ firephp: type: ~ level: ~ 我得到一个 ErrorException Couldn't find constant Monolog\Logger:: Monolog Couldn't find constant Monolog\Logger:: 。 如果有人能指出一种覆盖独白设置的方法,我将非常感激。 谢谢! 回答1 最好将处理程序定义为空数组: monolog: handlers: [] UPD1:有特殊类型的记录器:test