Symfony 3.4 Use View Inside My Bundle

Symfony 3.4 Use view inside my bundle

The basic problem appears to be that in S3.4, twig template paths such as 'ListerListerBundle:Default:index.html.twig' are no longer supported.

Replace the path in the controller with:

'@ListerLister/Default/index.html.twig'

And all should be well. If you are ever not sure what the actual namespace prefix is then run:

bin/console debug:twig

to list them.

S3.3 still works fine so this is something that changed in 3.4. Supposed to be using the namespaced format anyways so this is not a big deal.

I did file an issue about this on github: https://github.com/sensiolabs/SensioGeneratorBundle/issues/587

We shall see what the maintainers have to say.

Update: The great and powerful Fabpot himself replied to my issue. If you want to keep using the 'ListerListerBundle:Default:index.html.twig' format for templates then edit your app/config/config.yml file:

# app/config/config.yml
framework:
templating:
engines: ['twig']

You should only do this if you have legacy code which still uses the old format. Use twig namespaces for all new code.

How to generate the view files inside the bundle in Symfony2?

The base path of the generated templates is hard-coded.

Before symfony3, the line that define the path of the views was :

$dir = sprintf('%s/Resources/views/%s', $this->bundle->getPath(), str_replace('\\', '/', $this->entity));

And since symfony3 it is :

$dir = sprintf('%s/Resources/views/%s', $this->rootDir, str_replace('\\', '/', strtolower($this->entity)));

As you can see, before the bundle path was used. Now, it's the kernel.root_dir.

Also, the only alternative you have to override the default behavior is to override the Sensio\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator and change the default path depending on the entity of the generated CRUD.

Look at the old versions of the command, maybe they can help you.

Create views with CRUD Doctrine inside a custom Bundle

Well, that command don't have any options for that. You can see all the available options in the official documentation. But if you really need that then you must override the SensioGeneratorBundle, you can see how to extend any bundle in here. Then override the php class vendor/sensio/generator-bundle/Generator/DoctrineCrudGenerator.php, then find the action
"generate" and locate this line:

$dir = sprintf('%s/Resources/views/%s', $this->rootDir, str_replace('\\', '/', strtolower($this->entity)));

replace with:

$dir = sprintf('%s/Resources/views', $this->rootDir);

I have not tried it but in theory that should work. Since you have the intention to create all the views in there then maybe you need to override the name for each generated view, you can see an action for each one below in that class.

Hope this help you.



Related Topics



Leave a reply



Submit