[英]Symfony2 - The class 'X' was not found in the chain configured namespaces
I've been searching forever to solve my problem. 我一直在寻找解决我的问题。 But I can't find any solution. 但我找不到任何解决方案。
I always get this error message when I try to open the homepage: 我尝试打开主页时总是收到此错误消息:
Uncaught exception 'Doctrine\\Common\\Persistence\\Mapping\\MappingException' with message 'The class 'Test\\Bundle\\UserBundle\\Entity\\User' was not found in the chain configured namespaces ' in... 未捕获的异常'Doctrine \\ Common \\ Persistence \\ Mapping \\ MappingException',消息'在'链配置的命名空间'中找不到类'Test \\ Bundle \\ UserBundle \\ Entity \\ User'...
The weird thing is that I only get it when I have following URL: 奇怪的是,当我有以下网址时,我才会得到它:
http://localhost/ HTTP://本地主机/
But when I run it on this URL I don't get any error and my page is being displayed correctly: 但是当我在这个URL上运行它时,我没有收到任何错误,我的页面正确显示:
http://localhost/app_dev.php HTTP://localhost/app_dev.php
My Configuration looks like this (config.yml): 我的配置看起来像这样(config.yml):
# Doctrine Configuration
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
test:
driver: "%database_driver2%"
host: "%database_host2%"
port: "%database_port2%"
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
TestUserBundle:
type: annotation
And I call Doctrine in my custom service like this: 我在我的自定义服务中调用Doctrine,如下所示:
public function __construct(EntityManager $em)
{
$repositiory = $em->getRepository('Test\Bundle\UserBundle\Entity\User');
$this->user = $repositiory->find($_SERVER['AUTH_USER']);
}
My Symfony Application is running on an IIS Webserver. 我的Symfony应用程序正在IIS Web服务器上运行。
Do you guys know where I made a mistake? 你们知道我弄错了吗?
Mapping name is TestUserBundle
but the path is Test\\Bundle\\User\\Bundle
, shouldn't it be named TestBundleUserBundle
instead? 映射名称是TestUserBundle
但路径是Test\\Bundle\\User\\Bundle
,不应该将其命名为TestBundleUserBundle
吗? Also, usually the mappings
and auto_generate_proxy_classes
are set to true
in dev mode which might explain why it's working there and not in prod. 此外,通常在开发模式下将mappings
和auto_generate_proxy_classes
设置为true
,这可能解释了为什么它在那里工作而不是prod。
You might want to checkout the documentation (Symfony 2.7) which shows how exactly you should be configuring the mappings depending on your case. 您可能需要查看文档 (Symfony 2.7),该文档根据您的具体情况显示您应该如何配置映射。
doctrine:
# ...
orm:
# ...
auto_mapping: true
mappings:
# ...
AppBundle:
type: xml
dir: SomeResources/config/doctrine
doctrine:
# ...
orm:
# ...
mappings:
# ...
SomeEntityNamespace:
type: annotation
dir: "%kernel.root_dir%/../src/Entity"
is_bundle: false
prefix: App\Entity
alias: App
Last, but not least, always clear your cache directory after applying changes to the config.yml
or files in the app/config/
directory. 最后,但并非最不重要的是,在对config.yml
或app/config/
目录中的文件应用更改后,始终清除缓存目录。
As mentioned in the comments: You need to temporarily stop any PHP processes that might be using the prod directory (ie if you've ran console server:run) and try again. 如评论中所述:您需要暂时停止可能正在使用prod目录的任何PHP进程(即,如果您已运行控制台服务器:运行)并再次尝试。 If that doesn't do it, try this 如果不这样做,试试这个
It turns out that my mistake was that I forgot to add distant bundles/bundles in "vendor" inside my AppKernel file. 事实证明,我的错误是我忘记在我的AppKernel文件中的“vendor”中添加远程bundle / bundles。
They weren't registered in the "registerBundles" function. 它们未在“registerBundles”功能中注册。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.