Answer the question
In order to leave comments, you need to log in
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);
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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question