This tutorial is built using Symfony 4, but most of the concepts apply fine to Symfony 5!
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"doctrine/annotations": "^1.8", // v1.8.0
"knplabs/knp-markdown-bundle": "^1.7", // 1.7.0
"knpuniversity/lorem-ipsum-bundle": "*@dev", // dev-master
"nexylan/slack-bundle": "^2.0,<2.2", // v2.0.1
"php-http/guzzle6-adapter": "^1.1", // v1.1.1
"sensio/framework-extra-bundle": "^5.1", // v5.1.6
"symfony/asset": "^4.0", // v4.0.6
"symfony/console": "^4.0", // v4.0.6
"symfony/flex": "^1.0", // v1.21.6
"symfony/framework-bundle": "^4.0", // v4.0.6
"symfony/lts": "^4@dev", // dev-master
"symfony/twig-bundle": "^4.0", // v4.0.6
"symfony/web-server-bundle": "^4.0", // v4.0.6
"symfony/yaml": "^4.0", // v4.0.6
"weaverryan_test/lorem-ipsum-bundle": "^1.0" // v1.0.0
},
"require-dev": {
"easycorp/easy-log-handler": "^1.0.2", // v1.0.4
"sensiolabs/security-checker": "^4.1", // v4.1.8
"symfony/debug-bundle": "^3.3|^4.0", // v4.0.6
"symfony/dotenv": "^4.0", // v4.0.6
"symfony/maker-bundle": "^1.0", // v1.1.1
"symfony/monolog-bundle": "^3.0", // v3.2.0
"symfony/phpunit-bridge": "^3.3|^4.0", // v4.3.3
"symfony/stopwatch": "^3.3|^4.0", // v4.0.6
"symfony/var-dumper": "^3.3|^4.0", // v4.0.6
"symfony/web-profiler-bundle": "^3.3|^4.0" // v4.0.6
}
}
11 Comments
Hey thatnk you about the tuto, what's the best practice is it better to set your code under src/ or bunde/!! I really need a raison for this!
Hey @Fabien
Since Symfony 3.4 (I believe! but definitely since Symfony4) the internal bundle structure of your application doesn't exist anymore. The reason is simple, that structure was confusing, and Symfony does not want to impose you a specific structure. So, the new standard is to put all your application code inside
src/Cheers!
I find the following part of this tutorial really interesting:
$definition->setArgument(0, new Reference($config['word_provider']));
What is the reason you can't access correctly with container->get (it throws the error: You have requested a non-existent service):
Example
$definition->setArgument(0, $container->get($config['word_provider']));
Hey Rainer S.
That's a good question! And here a pretty simple answer: We can't get real service at this step of container building, probably this services are not instantiated, so that's why we need to do a reference to service which we need here when everything will be instantiated!
Cheers!
Interesting behavior: if I put CustomWordProvider.php in src folder of the bundle (instead of App\Service folder). It doesn't work. It writes: services not found.
Hey triemli
You can't just move file to another spot, you should also change namespace and fix service definition.
Cheers!
Thank you for everything I am learning with these tutorials, but i think this course needs some tutorials about the use of templates and also overwrite it . Is that possible?
Hey Jose!
But you probably want to use and overwrite templates from third-party bundles in *your* project, so this topic does not relate to this course too much as we show how to create third-party bundles here. But we do have some courses where we explain how to override third-party templates, e.g. you can check it out in FOSUserBundle course: https://symfonycasts.com/sc...
I hope this helps.
Cheers!
No, I want to do it in my own Bundle, ie create my own Bundle as explained in this course, but make use of templates, which I think is the only thing missing in this course, together with recipes.
Thanks and I apologize for my English.
Hey Jose carlos C.!
Sorry for my slow reply! You have a great question! So let me do my best to answer it :).
When you render a template in a bundle, there are 2 things to know:
1) You should put them in the
Resources/viewsdirectory of the bundle. You can see examples of this in, for example, FOSUserBundle: https://github.com/FriendsOfSymfony/FOSUserBundle/tree/master/Resources/views2) When you render those templates, you should use a special syntax. For example, suppose you have a
Resources/views/products/checkout.html.twigfile. And, your bundle is calledSymfonyCastsTemplateBundle:). Then, when you render a template, you would use the string'@SymfonyCastsTemplate/products/checkout.html.twig'. Yep, it's literally the@symbol, then the name of your bundle, but without the Bundle word on the end. Symfony will know to look in the Resources/views directory of the bundle with this syntax.And, as a bundle author, that's all you need to do. With this setup, any users of your bundle will be able to override your templates by following the standard directions - https://symfony.com/doc/current/bundles/override.html#templates - you don't need to do anything special to allow them to override the templates.
I hope this helps! If you have more questions, please let me know!
Cheers!
Thank you very much for the answer, I think with this explanation is more than enough to do it.
Thank you again!
"Houston: no signs of life"
Start the conversation!