ruudy
ruudy

Reputation: 491

Extend Crud Generator on Symfony2

I know how to extends or override the crud generator views, creating the files like documendation says:

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

But i want to reuse that views and i dont wanna put the views in the same Bundle where i have Entities and the crud Controllers, Forms and Views will be created, so im trying to generate my own command and extend 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();
  }

}

I tryed 2 pieces of code i found on getGenerator function and im getting:

 [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

Of course i have the same folders tree like SensioGenerator Bundle have as skeleton, but only some files to override, i want that it takes from my bundle just the files i declare, its must take defualt files if not exists on me bundle.

I dont know if this is the right way to do that and what i miss up.

Thanks you in advice!

Upvotes: 0

Views: 985

Answers (1)

szecsikecso
szecsikecso

Reputation: 301

You missed to declare the function with parameter: protected function getGenerator(BundleInterface $bundle = null) and use Symfony\Component\HttpKernel\Bundle\BundleInterface;

Upvotes: 2

Related Questions