I’ve got a Symfony 1.4 app that I’ve inherited to maintain and update. One thing that I’m having trouble understanding/figuring out is how to use the same template/action name for both a load and a post.
Coming from a Struts2 background, I can reuse the same action for both methods, but have a get point to a “input” method whereas a post would point to a “execute” method. But I can’t seem to find a similar workflow in Symfony.
Given that the same template is used in both a get and a post, and I would like to use the same action name, how can I specify a different method name for each type?
For example, for a login form, I would like to create a Login action, with a “input” method that basically displays the template, and upon submission, it would go to an execute method to validate the data before redirecting or redisplaying the form with the errors.
I realize that I could put in an if ($request->isMethod(‘POST’)) at the top of my execute method, but I presume there must be a better/more conventional way of doing this. I presume that there must be something in symfony to allow for this, but I just haven’t been able to find it.
Can anyone point me in the right direction?
What you’re looking for is Routing. You can route HTTP Request Methods in Symfony.
Here’s the documentation: http://symfony.com/legacy/doc/reference/1_4/en/10-Routing
An example of what you would like to do would be structured like this: