Alex
Alex

Reputation: 7688

How to route in symfony2?

Well, having the following in my routing_dev.yml

_welcome:
    pattern:  /
    defaults: { _controller: AcmeDemoBundle:Welcome:index }

homepage:
    pattern:   /
    defaults: { _controller: AcmeDemoBundle:Ideup:index }

aboutme:
    pattern:   /aboutme
    defaults: { _controller: AcmeDemoBundle:Ideup:about }

_ideup:
    resource: "@AcmeDemoBundle/Controller/IdeupController.php"
    type:     annotation
    prefix:   /ideup

_form:
    resource: "@AcmeDemoBundle/Controller/FormController.php"
    type:     annotation

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_main:
    resource: routing.yml

I'm trying to have a simple form:

<form action="{{ path('_form') }}" method="POST" id="contact_form">

But I keep getting this following exception: "Route "_form" does not exist."

I just don't know where else to look and what to do, any ideas?

Upvotes: 2

Views: 178

Answers (1)

smottt
smottt

Reputation: 3330

_form:
  resource: "@AcmeDemoBundle/Controller/FormController.php"
  type:     annotation

This will just load annotated routes from the FormController.

For example:

/**
 * @Route("/my/route", name="my_route")
 */
public function myRouteAction() { ... }

If you want a _form route, you should either load all annotationed routes from the FormController or define it in another way:

_form:
  pattern: /path/to/your/form
  defaults: { _controller: AcmeDemoBundle:Form:myFormAction }

Of course myFormAction() should exist in the FormController.

Upvotes: 3

Related Questions