2012年9月10日 星期一

symfony the_big_picture

http://symfony.com/doc/current/quick_tour/the_big_picture.html

The Symfony2 Standard Edition uses YAML for its configuration files

supports XML, PHP, and annotations natively

may be used interchangeably within an application

Redirecting and Forwarding

return $this->redirect($this->generateUrl('_demo_hello', array('name' => 'Lucas')));
The generateUrl() is the same method as the path() function we used in templates. It takes the route name and an array of parameters as arguments and returns the associated friendly URL

forward the action to another one with the forward() method. Internally, Symfony makes a "sub-request", and returns the Response object from that sub-request:
1
2
3
$response = $this->forward('AcmeDemoBundle:Hello:fancy', array('name' => $name, 'color' => 'green'));

// ... do something with the response or return it directly



In a template, you can also access the Request object via the app.request variable:
1
2
3
{{ app.request.query.get('page') }}

{{ app.request.parameter('page') }}


You can also store small messages that will only be available for the very next request:
1
2
3
4
5
// store a message for the very next request (in a controller)
$session->setFlash('notice', 'Congratulations, your action succeeded!');

// display the message back in the next request (in a template)
{{ app.session.flash('notice') }}
This is useful when you need to set a success message before redirecting the user to another page (which will then show the message).




沒有留言:

張貼留言