douya1061 2015-09-17 16:53
浏览 82
已采纳

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

I have this: src/app/config/routing.yml

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

src/AppBundle/Controller/DefaultController.php (code only for the edit controller)

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/Entity/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

When accessing localhost:8000/edit?id=node_id for my node I get this:

Unable to guess how to get a Doctrine instance from the request information. 500 Internal Server Error - LogicException

I don't understand why. My class is simple and the table is simple also. Can someone explain to me why the symfony_demo works and my example doesn't? Thank you.

  • 写回答

1条回答 默认 最新

  • dongshai2022 2015-09-17 22:07
    关注

    OK It looks like it was my fault. I wasn't using routing placeholders, which would point to the node on which I want to execute the edit action. So, in src/app/config/routing.yml I should have had this:

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

    Thank you msypes from #symfony IRC room for the answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog