不存在类别或接口:“ Symfony \ config \ doctrineconfig”

发布于 2025-02-10 13:59:12 字数 1695 浏览 1 评论 0原文

我正在尝试以编程方式添加一个实体管理器,参考此文档: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文