我一直在寻找解决我的问题的方法。但我找不到任何解决办法。
当我尝试打开主页时,总是收到此错误消息:
未捕获的异常“Doctrine\Common\Persistence\Mapping\MappingException”,消息为“在链配置的命名空间中找不到类“Test\Bundle\UserBundle\Entity\User”...
奇怪的是,只有当我有以下 URL 时我才得到它:
http://本地主机/ http://localhost/
但是当我在此 URL 上运行它时,我没有收到任何错误,并且我的页面显示正确:
http://localhost/app_dev.php http://localhost/app_dev.php
我的配置如下所示(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
我在自定义服务中这样调用 Doctrine:
public function __construct(EntityManager $em)
{
$repositiory = $em->getRepository('Test\Bundle\UserBundle\Entity\User');
$this->user = $repositiory->find($_SERVER['AUTH_USER']);
}
我的 Symfony 应用程序正在 IIS Web 服务器上运行。
你们知道我哪里做错了吗?
映射名称是TestUserBundle
但路径是Test\Bundle\User\Bundle
,不应该命名为TestBundleUserBundle
反而?另外,通常情况下mappings
and auto_generate_proxy_classes
被设置为true
在开发模式下,这可能可以解释为什么它在那里工作而不是在生产模式下工作。
您可能想查看文档 http://symfony.com/doc/current/reference/configuration/doctrine.html#custom-mapping-entities-in-a-bundle(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
最后但并非最不重要的一点是,在应用更改后,请务必清除缓存目录config.yml
或文件中的app/config/
目录。
正如评论中提到的:
您需要暂时停止任何可能正在使用 prod 目录的 PHP 进程(即,如果您已运行控制台服务器:运行),然后重试。如果这不起作用,请尝试this https://stackoverflow.com/questions/97875/rm-rf-equivalent-for-windows
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)