1 pièce(s) jointe(s)
The class 'Ma Classe' was not found in the chain configured namespaces App Entity Main, FOS UserBundle Model
Bonjour à tous,
J'ai réalisé une architecture multiconnexion(multi base de données) pour mon projet symfony4. J'ai créé un ApiController.php pour changer de connexion en utilisant "/ {db}" afin que je puisse l'utiliser dans d'autres controllers :
Pièce jointe 488087
ApiController.php :
Code:
1 2 3 4 5 6 7 8 9 10
| $this->em=$em;
$this->db=$requestStack->getCurrentRequest()->attributes->all()['db'];
//$dbName=$requestStack->getCurrentRequest()->attributes->all()['db'];
/** @var DossierConnection $connection */
$connection=$managerRegistry->getConnection('dossier');
$connection->changeParams($this->db, $this->dbUser, $this->dbPassword);
file_put_contents('connection.txt',$connection);
$connection->reconnect(); |
ApiTiersController.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <?php
namespace App\Controller\Api\Dossier;
use App\Entity\Dossier\Tiers;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/{db}/tiers")
*/
class ApiTiersController extends ApiController
{
/**
* @Route("/enregistrer", name="api_tiers_enregistrer", methods={"POST"})
* @param Request $request
* @return JsonResponse|RedirectResponse
*/
public function enregistrer( Request $request)
{
$data = json_decode($request->getContent(), true);
$tiers = new Tiers();
$tiers->setRs($data['rs']);
try {
$this->em->persist($tiers);
// $this->em->flush();
} catch (\Exception $e) {
return new JsonResponse(["Ajout Tiers" => "error on persisting ".$e->getMessage()], 500);
}
return new JsonResponse(["Ajout Tiers" => "ok"], 200);
}
} |
Tiers.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <?php
namespace App\Entity\Dossier;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\Dossier\TiersRepository")
*/
class Tiers
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id; |
et quand j'appel à : http://127.0.0.1:8000/api/base1/tiers/enregistrer je reçois ce message d'erreur :
Citation:
{ "Ajout Tiers": "error on persisting The class 'App\Entity\Dossier\Tiers' was not found in the chain configured namespaces App\Entity\Main, FOS\UserBundle\Model" }