Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcdb7064

Browse files
javiereguiluzweaverryan
authored andcommitted
[quick_tour] second pass to "the controller" chapter and
added a section about displaying error pages
1 parent2cd3bab commitcdb7064

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

‎quick_tour/the_controller.rst

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ variable in the route path instead::
5252
/**
5353
* @Route(
5454
* "/hello/{name}.{_format}",
55-
* defaults = {"_format"="html"},
56-
* requirements = {"_format"="html|xml|json"},
55+
* defaults = {"_format" ="html"},
56+
* requirements = {"_format" ="html|xml|json"},
5757
* name = "_demo_hello"
5858
* )
5959
* @Template()
@@ -88,6 +88,20 @@ method::
8888

8989
return $this->forward('AcmeDemoBundle:Hello:fancy', array('name' => $name, 'color' => 'green'));
9090

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+
91105
Getting information from the Request
92106
------------------------------------
93107

@@ -140,7 +154,7 @@ from any controller::
140154
$foo = $session->get('foo');
141155

142156
// use a default value if the attribute doesn't exist
143-
$filters = $session->get('filters',array());
157+
$foo = $session->get('foo','default_value');
144158
}
145159

146160
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)::
150164
// store a message for the very next request (in a controller)
151165
$session->getFlashBag()->add('notice', 'Congratulations, your action succeeded!');
152166

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

159170
Caching Resources
160171
-----------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp