[英]Symfony2 Doctrine ORM Manager named “customer” does not exist
Hello I coopied the example for using two different database connections from the Symfony2 documentation: Symfony2 multiple connections documentation So however Symfony does not find the the costumer entity manager. 您好,我整理了使用Symfony2文档中的两个不同数据库连接的示例: Symfony2多连接文档因此,Symfony找不到客户实体管理器。 (The parameters are defined properly) (参数定义正确)
doctrine:
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
customer:
driver: "%database_driver%"
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:
AppBundle: ~
customer:
connection: customer
mappings:
AppBundle: ~
The Controller looks like this: 控制器看起来像这样:
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$em = $this->get('doctrine')->getManager();
$em = $this->get('doctrine')->getManager('default');
$em = $this->get('doctrine.orm.default_entity_manager');
// Both of these return the "customer" entity manager
$customerEm = $this->get('doctrine')->getManager('customer');
$customerEm = $this->get('doctrine.orm.customer_entity_manager');
return $this->render('default/index.html.twig', array(
'base_dir' => realpath($this->container->getParameter('kernel.root_dir').'/..'),
));
}
I should get the costumer entity manager, but however Symfony throws an invalid argument exception with the message. 我应该获得客户实体管理器,但是Symfony会在消息中抛出一个无效的参数异常。
[2015-10-19 23:19:18] request.CRITICAL: Uncaught PHP Exception
InvalidArgumentException: "Doctrine ORM Manager named "customer" does
not exist." at /srv/www/htdocs/symfony/my_project_name/app/cache
/prod/classes.php line 7344 {"exception":"[object]
(InvalidArgumentException(code: 0): Doctrine ORM Manager named
\"customer\" does not exist. at /srv/www/htdocs/symfony/my_project_name
/app/cache/prod/classes.php:7344)"} []
I cleaned the cache with php app/console cache:clear but this does not help. 我用php app / console cache:clear清除了缓存,但这无济于事。
Artamiel had the right answer in a comment: Artamiel在一条评论中给出了正确的答案:
Symfony2 Doctrine ORM Manager named "customer" does not exist 不存在名为“客户”的Symfony2学说ORM管理器
cache:clear clears the dev environment by default, but looking at your error log, you receive the error in your prod environment. cache:clear默认情况下会清除开发环境,但查看错误日志后,您会在生产环境中收到错误。 To clear the cache on your production environment, add -e prod flag, like this cache:clear -e prod and refresh your page. 要清除生产环境中的缓存,请添加-e prod标志,例如此cache:clear -e prod并刷新页面。
First, I think, one declaration of entity manager in your controller is enough: 首先,我认为,在控制器中声明一个实体管理器就足够了:
/ *** /
public function indexAction(Request $request)
{
$em = $this->get('doctrine')->getManager('default');
$customerEm = $this->get('doctrine')->getManager('customer');
/ *** /
}
Second, are you sure that you can declare the same bundle in your mapping configuration ( AppBundle: ~
in this case) ? 其次,您确定可以在映射配置中声明相同的AppBundle: ~
包(在这种情况下为AppBundle: ~
)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.