Answer the question
In order to leave comments, you need to log in
Error when adding a new database connection. Where to fix namespace?
Added another connection to the database, but the error " The class 'App\Entity\MealSQL\Data' was not found in the chain configured namespaces App\Entity\MealSQL> " appears.
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
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
]);
}
}
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