EmilCataranciuc
EmilCataranciuc

Reputation: 1041

symfony 2.7.4 + doctrine/orm 2.4.8 = Unable to guess how to get a Doctrine instance from the request information

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.

Upvotes: 1

Views: 877

Answers (1)

EmilCataranciuc
EmilCataranciuc

Reputation: 1041

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.

Upvotes: 0

Related Questions