【发布时间】:2023-12-18 18:38:01
【问题描述】:
我是 Symfony 的新手,正在尝试使用 Acme/LibraryBundle 显示表单。
但是有一个错误
“在 AcmeLibraryBundle:Book:new.html.twig 中的模板渲染过程中引发了异常(“无法为命名路由“book_new”生成 URL,因为这样的路由不存在。”) 3.”
我的表格
<form action="{{ path('book_new') }}" method="post" {{ form_enctype(form) }}>
{{ form_widget(form) }}
<input type="submit" />
</form>
我的控制器:
namespace Acme\LibraryBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Acme\DemoBundle\Model\Book;
use Acme\LibraryBundle\Form\Type\BookType;
class BookController extends Controller
{
public function newAction()
{
$book = new Book();
$form = $this->createForm(new BookType(), $book);
/*$request = $this->getRequest();
if ('POST' === $request->getMethod()) {
$form->handleRequest($request);
if ($form->isValid()) {
$book->save();
return $this->redirect($this->generateUrl('book_success'));
}
}*/
return $this->render('AcmeLibraryBundle:Book:new.html.twig', array(
'form' => $form->createView(),
));
}
}
【问题讨论】: