W
W
w_b_x2019-02-10 19:39:56
symfony
w_b_x, 2019-02-10 19:39:56

How to solve "must be an instance of Symfony...." error?

Hello.
An unexpected problem appeared, for some reason the code that worked an hour ago began to give an error and I cannot understand its roots.
The code:

<?php

require __DIR__.'/../vendor/autoload.php';
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use App\Entity\Account; // Подключаю объект account, который прекрасно работает из Symfony

$isDevMode = true;
$entitiesPaths = array(__DIR__.'/../Entity');
$dbParams = array(
    'dbname' => 'База',
    'user' => 'Логин',
    'password' => 'Пароль',
    'host' => '127.0.0.1',
    'driver' => 'pdo_mysql',
);
$config = Setup::createAnnotationMetadataConfiguration($entitiesPaths, $isDevMode, null, null, false);
$em = \Doctrine\ORM\EntityManager::create($dbParams, $config);
$id = 9; // для примера
$account = $em->getRepository(Account::class)->findOneBy([
    'id'=>$id,
]);
var_dump($account);

I am getting this error:
Fatal error: Uncaught TypeError: Argument 1 passed to App\Repository\AccountRepository::__construct() must be an instance of Symfony\Bridge\Doctrine\RegistryInterface, instance of Doctrine\ORM\EntityManager given, called in _путь к проекту_\vendor\doctrine\orm\lib\Doctrine\ORM\Repository\DefaultRepositoryFactory.php on line 68 and defined in _путь к проекту_\src\Repository\AccountRepository.php:17

It follows from the error that something is wrong in the Entity Account, but it was created using php bin/console make:entity, did not change and works from Symfony controllers, just like AccountRepository.
With what it can be connected?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question