@@ -52,8 +52,8 @@ variable in the route path instead::
52
52
/**
53
53
* @Route(
54
54
* "/hello/{name}.{_format}",
55
- * defaults = {"_format"= "html"},
56
- * requirements = {"_format"= "html|xml|json"},
55
+ * defaults = { "_format" = "html" },
56
+ * requirements = { "_format" = "html|xml|json" },
57
57
* name = "_demo_hello"
58
58
* )
59
59
* @Template()
@@ -88,6 +88,20 @@ method::
88
88
89
89
return $this->forward('AcmeDemoBundle:Hello:fancy', array('name' => $name, 'color' => 'green'));
90
90
91
+ Displaying error pages
92
+ ----------------------
93
+
94
+ Errors will inevitably happen during the execution of every web application.
95
+ In the case of ``404 `` errors, Symfony includes a handy shortcut that you can
96
+ use on your controllers::
97
+
98
+ throw $this->createNotFoundException();
99
+
100
+ For ``500 `` errors, just throw a regular PHP exception inside the controller and
101
+ Symfony will transform it in a proper ``500 `` error page::
102
+
103
+ throw new \Exception('Something went wrong!');
104
+
91
105
Getting information from the Request
92
106
------------------------------------
93
107
@@ -140,7 +154,7 @@ from any controller::
140
154
$foo = $session->get('foo');
141
155
142
156
// use a default value if the attribute doesn't exist
143
- $filters = $session->get('filters ', array() );
157
+ $foo = $session->get('foo ', 'default_value' );
144
158
}
145
159
146
160
You can also store "flash messages" that will auto-delete after the next request.
@@ -150,11 +164,8 @@ redirecting the user to another page (which will then show the message)::
150
164
// store a message for the very next request (in a controller)
151
165
$session->getFlashBag()->add('notice', 'Congratulations, your action succeeded!');
152
166
153
- // display any messages back in the next request (in a template)
154
-
155
- {% if app.session.flashbag.has('notice') %}
156
- <div>{{ app.session.flashbag.get('notice') }}</div>
157
- {% endfor %}
167
+ // display the flash message in the template
168
+ <div>{{ app.session.flashbag.get('notice') }}</div>
158
169
159
170
Caching Resources
160
171
-----------------
0 commit comments