1
出於某種原因,我無法生成我爲表單生成器指定的路由。如你所見,我指定了generateUrl('/ login'),但是,在表單構建期間,錯誤「無法爲指定路由生成URL」/ login「,因爲這樣的路由不存在。」Symfony2 GenerateUrl with annotation
路由/登錄是使用註釋在下面聲明的,什麼似乎是問題?我的應用程序控制器被設置爲使用註釋。
/**
* @Route("/")
* @Template()
*/
public function indexAction() {
$user = new User();
$form = $this->createFormBuilder($user)
->setAction($this->generateUrl('/login'))
->setMethod('POST')
->add('username', 'text')
->add('password', 'text')
->add('submit', 'submit')
->getForm();
$content = $this->renderView('ThisBundleBundle:Login:index.html.twig', array(
'form' => $form->createView(),
));
return new Response($content);
}
/**
* @Route("/login")
* @Template()
*/
public function loginAction() {
}
的routing.yml在應用程序:
bill_ThisBundleBundle: 資源: 「@ ThisBundleBundle /控制器/」 類型:註釋 前綴:/
您可以使用$ this-> generateUrl('bill_this_controller_login'),其中bill是src文件夾,這是軟件包名稱,controller是控制器的名稱,login是操作名稱。 –