Добавил еще одно подключение к БД, но выходит ошибка "
The class 'App\Entity\MealSQL\Data' was not found in the chain configured namespaces App\Entity\MealSQL>".
Doctrine.yaml
doctrine:
dbal:
default_connection: default
connections:
default:
url: '%env(resolve:DATABASE_URL)%'
mssql:
# configure these for your database server
url: '%env(DATABASE_MSSQL_URL)%'
driver: 'php_pdo_sqlsrv_74_ts_x64'
charset: utf8mb4
mealSql:
url: '%env(resolve:DATABASE_MEAL_MYSQL_URL)%'
orm:
auto_generate_proxy_classes: true
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/MySql'
prefix: 'App\Entity\MySql'
alias: App
mssql:
connection: mssql
mappings:
Mssql:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/NewElevatorMsSQL'
prefix: 'App\Entity\NewElevatorMsSQL'
alias: NewElevatorMsSQL
mealSql:
connection: mealSql
mappings:
MealSQL:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/MealSQL'
prefix: 'App\Entity\MealSQL>'
alias: MealSQL
В Data.php указан
namespace App\Entity\MealSQL. В контроллере:
use App\Entity\MealSQL\Data;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class MealController extends AbstractController
{
/**
* @Route("/meal", name="meal")
*/
public function index()
{
$em = $this->getDoctrine()->getManager('mealSql')->getRepository(Data::class);
$model = $em->find(21);
return $this->json([
'data' => $model
]);
}
}
Подключение к данной БД есть, так как сущность создана через
doctrine:mapping:import "App\Entity\MealSQL" annotation --path=src/Entity/MealSQL --em=mealSql