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.

图片转代码服务由CSDN问答提供 功能建议

我有这个: src / app / config / routing.yml

  app_block_edit:
 path:/ edit 
 defaults:{_ control: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()){
返回$ this-> redirectToRoute('app_block_edit',array('id'=> $ block-> getId())); 
} 
 \  n返回$ this-> render('admin / edit.html.twig',array(
'block'=> $ block,
'edit_form'=> $ editForm-> createView(),\  n)); 
} 
   
 
 

src / AppBundle / Entity / Block.php

  class Block \  n {
 private $ id; 
 private $ title; 
 private  $ content; 
。
。
。
   
 
 

src / AppBundle / Resources / config / doctrine / Block.orm.yml mapping \ n

  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条回答 默认 最新

相关推荐 更多相似问题