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
Executing Multiple SQL Queries in One Statement with PHP
PHP Include Error Not Findind the Path
$_Server["Remote_Addr"] Gives Server Ip Rather Than Visitor Ip
How to Add Text to an Image with PHP Gd Library
Python Equivalent of PHP's Compact() and Extract()
PHP Pdo Prepare Repetitive Variables
MVC (Laravel) Where to Add Logic
How to Fix Stream_Socket_Enable_Crypto(): Ssl Operation Failed with Code 1
How to Replace (Monkeypatch) PHP Functions
Difference Between Array_Map, Array_Walk and Array_Filter
How to Enable PHP's Openssl Extension to Install Composer
How to Run PHP Files on My Computer
PHP Sentence Boundaries Detection
Calculate Difference Between Two Dates Using Carbon and Blade