不存在类别或接口:“ Symfony \ config \ doctrineconfig”
我正在尝试以编程方式添加一个实体管理器,参考此文档: https://symmfony.com/doc/6.0/doc/6.0/doctrine/multipline/multiple_entity_entity_managers.mmanagers.htity_managers.htemll
但是,它需要动态创建,因此我由控制器触发它。不幸的是,Symfony没有找到Doctrineconfig类...尽管在文档中指定。
namespace App\Controller;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Config\DoctrineConfig;
class AdministrationController extends AbstractController
{
#[Route('/api/create-org', methods:['POST'])]
public function setUpNewOrg(DoctrineConfig $doctrine)
{
$doctrine->dbal()
->connection('test')
->url('postgresql://Test:test1234127.0.0.1:5432/testDB')
->serverVersion('13')
->charset('utf8');
$emNew = $doctrine->orm()->entityManager('test');
$emNew->mapping('test')
->isBundle(false)
->type('annotation')
->dir('%kernel.project_dir%/src/Entity')
->prefix('App\Entity')
->alias('App');
return $this->json([ 'message' => 'configured' ]);
}
}
但是,这导致以下错误消息:
无法解决参数$学说 “ App \ Controller \ AdministionController :: SetupNeworg()”:不能 确定控制器参数 “ App \ Controller \ AdministryController :: SetupNeworg()”: $ Doctrine参数是由不存在的类或 接口:“ Symfony \ config \ doctrineconfig”。
这只是在控制器中不起作用吗?
Symfony版本:6.0.7 PHP版本:8.1.6
I'm trying to programmatically add an entity-manager, with reference to this documentation:
https://symfony.com/doc/6.0/doctrine/multiple_entity_managers.html
However, it needs to be created dynamically, so I'm triggering it by a controller. Unfortunately Symfony does not find the DoctrineConfig class ... although specified as in the docs.
namespace App\Controller;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Config\DoctrineConfig;
class AdministrationController extends AbstractController
{
#[Route('/api/create-org', methods:['POST'])]
public function setUpNewOrg(DoctrineConfig $doctrine)
{
$doctrine->dbal()
->connection('test')
->url('postgresql://Test:test1234127.0.0.1:5432/testDB')
->serverVersion('13')
->charset('utf8');
$emNew = $doctrine->orm()->entityManager('test');
$emNew->mapping('test')
->isBundle(false)
->type('annotation')
->dir('%kernel.project_dir%/src/Entity')
->prefix('App\Entity')
->alias('App');
return $this->json([ 'message' => 'configured' ]);
}
}
However, this leads to following error message:
Cannot resolve argument $doctrine of
"App\Controller\AdministrationController::setUpNewOrg()": Cannot
determine controller argument for
"App\Controller\AdministrationController::setUpNewOrg()": the
$doctrine argument is type-hinted with the non-existent class or
interface: "Symfony\Config\DoctrineConfig".
Does this just not work within a Controller?
Symfony version: 6.0.7
PHP version: 8.1.6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论