나는 단순화 된 컨트롤러를 사용하며 서비스 컨테이너가 없습니다. 저는 교리를 봉사에 주입하려고합니다.symfony2 서비스에 doctrine을 삽입하는 방법
다음ContextErrorException: Catchable Fatal Error: Argument 1 passed to Acme\Controller\WebController::__construct() must be an instance of Doctrine\ORM\EntityManager, none given, called in /home/hcs/Core/app/cache/dev/appDevDebugProjectContainer.php on line 3036 and defined in /home/hcs/Core/src/Acme/Controller/WebController.php line 28
내 서비스 데프입니다 : 여기에 오류가
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
orm:
mappings:
Acme:
type: annotation
dir: %kernel.root_dir%/../src/Acme/Model
prefix: Acme\Model
alias: Model
is_bundle: false
services:
WebController:
class: Acme\Controller\WebController
arguments: [@doctrine.orm.entity_manager ]
parent: elnur.controller.abstract
그리고 내 클래스
여기use Doctrine\ORM\EntityManager;
/**
* @Service("WebController", parent="elnur.controller.abstract")
*/
class WebController extends AbstractController
{
protected $em;
public function __construct(EntityManager $em)
{
$this->em = $em;
}
는 SF2 컨테이너 (PHP 응용 프로그램/콘솔 컨테이너에서 출력은 다음과 같습니다 디버그 | grep -i enity)
doctrine.orm.default_entity_manager container EntityManager5330e85ad5afb_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrine\ORM\EntityManager
doctrine.orm.entity_manager n/a alias for doctrine.orm.default_entity_manager
doctrine.orm.validator.unique container Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator
form.type.entity container Symfony\Bridge\Doctrine\Form\Type\EntityType
translator container Symfony\Component\Translation\IdentityTranslator
나는 서비스 정의에서 여전히 인수를 시도했다 : [ "@ doctrine.orm.entity_manager"]. 나는 캐시를 청소하려고했지만 EM이 주입 된 날의 삶은 불가능합니다. 내가 도대체 뭘 잘못하고있는 겁니까?
과 :
은 이제
@InjectParams
주석을 단순화 할 수 있습니까? '[ "@ doctrine.orm.entity_manager"]'는 arguements에 대해 작동해야합니다. – Chausserconfig.yml에 내 서비스를 정의하고 위의 인수로 제공하고 있습니다. 하지만 건설 시간에 위에서 언급 한 오류가 발생합니다. –
어떻게 구성하고 있습니까? '$ WebController = $ this-> get ('WebController'); 또는'$ WebController = new WebController()'를하고 계십니까? – Chausser