繁体   English   中英

在Symfony2上扩展Crud Generator

[英]Extend Crud Generator on Symfony2

我知道如何扩展或覆盖Crud Generator视图,创建文件documendation时说:

http://symfony.com/doc/current/bundles/SensioGeneratorBundle/index.html

但是我想重用这些视图,并且不想将视图放在具有实体和原始控制器的同一个Bundle中,因此将创建窗体和视图,因此我试图生成自己的命令并扩展GenerateDoctrineCrudCommand:

use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand;
use Sensio\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator;

class BackendCrudCommand extends GenerateDoctrineCrudCommand {

  protected $generator;

  protected function configure()
  {
    parent::configure();

    $this->setName('d2armory:generate:crud');
    $this->setDescription('Automatic crud generator based on templates!');
  }

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

    return $this->generator;
    //$generator = new DoctrineCrudGenerator($this->getContainer()->get('filesystem'), __DIR__.'/../Resources/skeleton/crud');
    //$this->setGenerator($generator);
    //return parent::getGenerator();
  }

}

我尝试了在getGenerator函数上发现的2条代码,即时消息得到了:

 [Symfony\Component\Debug\Exception\ContextErrorException]                                                                                                                                                                
 Runtime Notice: Declaration of XXX\BackendBundle\Command\BackendCrudCommand::getGenerator() should be compatible with Sensio\Bundle\GeneratorBundle\Command\GeneratorCommand::getGenerator(Symfony\Component\HttpKernel\Bundle\BundleInterface $bundle = NULL) in /home.../XXX/BackendBundle/Command/BackendCrudCommand.php line 38

当然,我具有与SensioGenerator Bundle相同的文件夹树作为骨架,但是只有一些要覆盖的文件,我希望它仅从我的包中获取我声明的文件,如果我的包中不存在该文件,则必须删除默认文件。

我不知道这是否是正确的方法以及我想念的是什么。

谢谢您的指教!

您错过了使用参数声明函数的方法:受保护的函数getGenerator(BundleInterface $ bundle = null)并使用Symfony \\ Component \\ HttpKernel \\ Bundle \\ BundleInterface;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM