0

I have this code in my template:

<form action="{{ path('wba_create') }}" method="post" {{ form_enctype(form) }}>
        {{ form_widget(form) }}
        <p>
            <button type="submit">Registrar</button>
        </p>
</form>

And in my controller I have this annotation:

   /**
     *
     * @Route("/", name="wba_create")
     * @Method("POST")
     */
    public function createAction(Request $request) {
        ....
    }

But in the rendered HTML I got just <form method="post" action="/app_dev.php/"> why? What I miss here?

Reynier
  • 2,420
  • 11
  • 51
  • 91

2 Answers2

1

There is nothing wrong with your code here ... you're configuring wba_create as route /

@Route("/", name="wba_create")

That's the trailing slash in /app_dev.php / ... app_dev.php is in the url because you're accessing the page through app_dev.php aka in the dev environment.

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
  • so, in order to execute `create` action when form is send what is the right code? I'm a bit lost here – Reynier Aug 01 '13 at 19:03
  • it is the right code as long as you want your submit url to be `/` ... What is your exact problem? If you submit the form it will be sent to `/` using http method POST. Your controller should receive the request. – Nicolai Fröhlich Aug 01 '13 at 19:04
  • I need to send the form data to `TestController/createAction()` wich will handle the form and save data using entities – Reynier Aug 01 '13 at 19:06
  • that's exactly what is currently happening with this code. Where are you hanging? Just put a simple `die('hello from testcontroller:create'); into your createAction to check wether the action is actually called ... submit the form and you'll see ... "hello from testcontroller:create" ... or don't you? – Nicolai Fröhlich Aug 01 '13 at 19:06
  • Ohhhh sorry I'm coming from Symfony1 and things change a bit, this is new for me! You're right I get redirected to create. Now if I've a show action defined in my annotation as `@Route("/{id}", name="wba_show")` I can redirect to that function using this `$this->redirect($this->generateUrl('wba_show', array('id' => $entity->getTypeId())));`? – Reynier Aug 01 '13 at 19:12
  • you got it - maybe add a default id or some requirement like d+ to your route annotation but that's basically it ;) – Nicolai Fröhlich Aug 01 '13 at 19:14
0

If you're running your Symfony application in development mode, every page is being treated by app_dev.php (including the page where your form is shown)

Your code should work, don't worry about the /app_dev.php/ added to the URL, it will not be there if you use the production environment.

Webberig
  • 2,746
  • 1
  • 23
  • 19