我有这个:src/app/config/routing.yml
app_block_edit:
path: /edit
defaults: { _controller: AppBundle:Default:edit }
methods: [GET, POST]
src/AppBundle/Controller/DefaultController.php(仅用于编辑控制器的代码)
public function editAction(Block $block, Request $request)
{
$editForm = $this->createForm(new BlockType(), $block);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
return $this->redirectToRoute('app_block_edit', array('id' => $block->getId()));
}
return $this->render('admin/edit.html.twig', array(
'block' => $block,
'edit_form' => $editForm->createView(),
));
}
src/AppBundle/实体/Block.php
class Block
{
private $id;
private $title;
private $content;
.
.
.
src/AppBundle/资源/config/理论/Block.orm。yml映射
AppBundle'Entity'Block:
type: entity
table: block
id:
id:
type: integer
generator:
strategy: AUTO
fields:
title:
type: string
content:
type: text
访问localhost:8000/edit?id=node_id对于我的节点,我得到这个:
无法猜测如何从请求信息中获取Doctrine实例。500内部服务器错误- LogicException
我不明白为什么。我的课很简单,表格也很简单。有人可以向我解释为什么symfony_demo工作,而我的例子没有?谢谢你。
好吧,看来是我的错。我没有使用路由占位符,这将指向我想在其上执行编辑操作的节点。所以,在src/app/config/routing。我应该有这个:
app_block_edit:
path: /edit/{id}
defaults: { _controller: AppBundle:Default:edit }
methods: [GET, POST]
感谢来自#symfony IRC聊天室的msypes的回答