1

エンティティマネージャーを使用したい基本的なコントローラーがあります:

<?php

namespace HanziGame\MainBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use HanziGame\MainBundle\Entity\Hanzi;

class DefaultController extends Controller
{
    public function indexAction()
    {       
    $em = $this->get('registry')->getEntityManager();

    return $this->render('HanziGameMainBundle:Default:index.html.twig');
    }
}

実行すると、次のエラーが表示されます。

You have requested a non-existent service "registry".
500 Internal Server Error - NonExistentServiceException

私は Symfony の本 (http://symfony.com/doc/2.0/book/doctrine/orm.html) に従っているようですが、問題を修正する方法がわかりません。何が表示されないのですか?

4

2 に答える 2

3

変化

$em = $this->get('registry')->getEntityManager();

$em = $this->get('doctrine')->getEntityManager();

このバージョンのSymfony2に基づいて私のために働いた:

http://symfony.com/download?v=Symfony_Standard_Vendors_2.0.0BETA1.tgz

于 2011-05-08T04:58:37.680 に答える
3

ベータ2で導入されたレジストリサービス。現在はマスターブランチにあります。

于 2011-05-05T12:36:43.547 に答える