[英]How to route in symfony2?
Well, having the following in my routing_dev.yml
好吧,在我的
routing_dev.yml
中包含以下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."
但是我一直收到以下异常:
"Route "_form" does not exist."
I just don't know where else to look and what to do, any ideas? 我只是不知道该去哪里看,做什么,有什么想法吗?
_form:
resource: "@AcmeDemoBundle/Controller/FormController.php"
type: annotation
This will just load annotated routes from the FormController. 这只会从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
路由,则应该从FormController加载所有带注释的路由,或者以其他方式定义它:
_form:
pattern: /path/to/your/form
defaults: { _controller: AcmeDemoBundle:Form:myFormAction }
Of course myFormAction()
should exist in the FormController
. 当然,
myFormAction()
应该存在于FormController
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.