简体   繁体   中英

Doctrine Exception (Symfony2)

On localhost works all fine. But when uploaded to the server throws this error. What could be wrong?

Uncaught exception 'Doctrine\\Common\\Persistence\\Mapping\\MappingException' with message 'The class 'Acme\\DemoBundle\\Entity\\User' was not found in the chain configured namespaces FOS\\UserBundle\\Entity, Acme\\BazaBundle\\Entity, FOS\\UserBundle\\Model'

http://baza.sysit.com.ua/web/

config.yml:

 fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Acme\DemoBundle\Entity\User

This is because you are referencing a class within a bundle that is not registered. You probably removed the initialization for the AcmeDemoBundle in the AppKernel.php but it still references it in your FOSUser config.

You will need to create a User entity for your bundle and reference it in user_class parameter under fos_user, or if you are using the AcmeDemoBundle to hold your User entity, then just re-initialize it in your AppKernel.php

The Acme bundle is by default only available in development and test environments. As long as you working on your localhost, it's not a problem. You are probably working in the development environment and in your app_kernel.php Acme\\DemoBundle is set to initialize only when the environment is dev or test. So it's working just fine.

On your server you're not accessing your site through the localhost. that means the development environment is not available. Your working on a production environment. Like I explained above, the production environment has no Acme\\DemoBundle initialized, so it can't find your user entity.

There are 2 possibilities:

  • go to your app-kernel.php: find the line "$bundles[] = new Acme\\DemoBundle\\AcmeDemoBundle();" and delete it. Then add the following line ("new Acme\\DemoBundle\\AcmeDemoBundle(),") to the first array of bundles.

  • create a new bundle and add it to your app.kernel.php and put your User class in that bundle.

If you're just creating a website for personal use, the first option may be the quickest and best option, but if you want your bundles to be named nice, you should use the last. good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM