- 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:

- HTML5+CSS3王者歸來
- Google Apps Script for Beginners
- Web應用系統開發實踐(C#)
- C#高級編程(第10版) C# 6 & .NET Core 1.0 (.NET開發經典名著)
- Visual Basic程序設計教程
- Java深入解析:透析Java本質的36個話題
- Unreal Engine 4 Shaders and Effects Cookbook
- Spring核心技術和案例實戰
- Vue.js 3.x高效前端開發(視頻教學版)
- ASP.NET本質論
- Python程序設計:基礎與實踐
- Learning Puppet
- Python實戰指南:手把手教你掌握300個精彩案例
- 計算機軟件項目實訓指導
- Python編程:從入門到實踐(第2版)