如何解决Symfony 4 在创建实体时使用错误的命名空间
我实际上遇到过几次这个问题,当使用 php bin/console make:entity 时,它为存储库中的 ManagerRegistry 使用了错误的命名空间。
这是它放在那里的内容:
use Doctrine\Persistence\ManagerRegistry;
然后出现以下错误:
Cannot autowire service "App\Repository\PrivateCallBookingAvailabilityRepository": argument "$registry" of method "__construct()" has type "Doctrine\Persistence\Manage
rRegistry" but this class was not found.
查看其他存储库并不总是这样做,实际使用的那些:
use Doctrine\Common\Persistence\ManagerRegistry;
知道为什么要这样做吗?
解决方法
您需要降级 symfony/maker-bundle
的版本,因为 Doctrine\Common\Persistence\ManagerRegistry
在 Doctrine 中被重命名为 Doctrine\Persistence\ManagerRegistry
,并且看起来您的 Doctrine 版本具有此类的旧名称。
您也可以选择将 Doctrine 更新到最新版本。
您可以在此处找到更多详细信息https://github.com/symfony/maker-bundle/pull/518。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。