Php 扩展Symfony2上的积垢发生器
我知道如何扩展或覆盖crud生成器视图,创建文件,如documendation所述: 但是我想重用这些视图,我不想将这些视图放在我拥有实体的同一个包中,crud控制器、表单和视图都将被创建,因此我试图生成自己的命令并扩展GeneratedActLineCrudCommand:Php 扩展Symfony2上的积垢发生器,php,symfony,bundle,Php,Symfony,Bundle,我知道如何扩展或覆盖crud生成器视图,创建文件,如documendation所述: 但是我想重用这些视图,我不想将这些视图放在我拥有实体的同一个包中,crud控制器、表单和视图都将被创建,因此我试图生成自己的命令并扩展GeneratedActLineCrudCommand: use Sensio\Bundle\GeneratorBundle\Command\GenerateDoctrineCrudCommand; use Sensio\Bundle\GeneratorBundle\Gener
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函数中找到的两段代码,我得到了:
[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捆绑包一样的文件夹树作为骨架,但只有一些文件要覆盖,我希望它只从我的捆绑包中获取我声明的文件,如果我的捆绑包中不存在,它必须获取default文件
我不知道这样做是否正确,我错过了什么
谢谢你的建议 您没有用参数声明函数: 受保护的函数getGenerator(BundleInterface$bundle=null)
并使用Symfony\Component\HttpKernel\Bundle\BundleInterface 你的问题到底是什么?这个通知让你烦恼吗?如果是这样的话,很明显出了什么问题。您覆盖了
GeneratorCommand
中的getGenerator()
,但没有指定最初提供的参数($bundle=NULL
)。编程时间太长,您是对的!解决这个问题后,现在我得到:[Twig\u Error\u Loader]命名空间“main”没有注册路径。请在问题中共享你的Twig文件代码。这可能会导致问题。