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')));
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 URLforward 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') }}
|
沒有留言:
張貼留言