symfony 2.7.4 + doctrine / orm 2.4.8 =无法猜测如何从请求信息中获取Doctrine实例

时间:2015-09-17 16:53:05

标签: php symfony orm doctrine-orm

我有这个: SRC /应用/配置/ 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 / Resources / config / doctrine / Block.orm.yml mapping

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有效,而我的例子却没有? 谢谢。

1 个答案:

答案 0 :(得分:0)

好吧看起来这是我的错。我没有使用路由占位符,它指向我想要执行编辑操作的节点。所以,在src / app / config / routing.yml中我应该有这个:

app_block_edit:
    path: /edit/{id}
    defaults: { _controller: AppBundle:Default:edit }
    methods: [GET, POST]

感谢来自#symfony IRC会议室的msypes的答案。