- Mastering Symfony
- Sohail Salehi
- 263字
- 2021-07-16 11:28:59
Custom bundles versus AppBundle
When we use AppBundle
as a code base, the app/
directory of our project can be seen as part of AppBundle
. Sure, it has other files and folders that take care of other bundles available in the /vendor
directory, for example, but we can benefit a lot from the app/
folder.
For example, if you look at the MyBundle/Resources
folder, you will find two subfolders named Resources/config/
and Resources/views/
, which hold service definitions (and other required settings in the future) and template files for that bundle.
However, with AppBundle
, we already have a folder named app/
, so conveniently, we can use the available app/config
for our configuration needs and app/Resources/views
for our templates. Using this approach, referencing these files are much easier.
Compare the render()
method in indexAction()
of each controller. In the AppBundle
controller, we simply referenced the template file without mentioning the name of the bundle. When there is no bundle name, Symfony by default looks in the app/Resources/views
directory to find the required template:
return $this->render('default/index.html.twig');
To check the contents of the app/Resources/views
directory use the following command:
$ tree app/Resources/views/ app/Resources/views/ ├── base.html.twig └── default └── index.html.twig
In MyBundle
, we have to mention the bundle name in the reference:
return $this->render('MyBundle:Default:index.html.twig');
We got two elements of MVC so far: Controller and View. Let's have a look at the big picture that we have now:

- Learning RxJava
- 構(gòu)建移動(dòng)網(wǎng)站與APP:HTML 5移動(dòng)開發(fā)入門與實(shí)戰(zhàn)(跨平臺(tái)移動(dòng)開發(fā)叢書)
- Hands-On Functional Programming with TypeScript
- RSpec Essentials
- Windows Embedded CE 6.0程序設(shè)計(jì)實(shí)戰(zhàn)
- Creating Data Stories with Tableau Public
- Python計(jì)算機(jī)視覺和自然語(yǔ)言處理
- Mastering Gephi Network Visualization
- 青少年學(xué)Python(第2冊(cè))
- Python編程快速上手2
- Mastering Unreal Engine 4.X
- 計(jì)算機(jī)程序的構(gòu)造和解釋(JavaScript版)
- Unity與C++網(wǎng)絡(luò)游戲開發(fā)實(shí)戰(zhàn):基于VR、AI與分布式架構(gòu)
- Scratch編程入門與算法進(jìn)階(第2版)
- Web前端開發(fā)全程實(shí)戰(zhàn):HTML5+CSS3+JavaScript+jQuery+Bootstrap