I am trying to implement a registration using the FOSUserBundle. I followed the tutorial at https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md
I updated my database using the php app/console doctrine:schema:update --force
command and all entries have been updated. But when I try to load my project in the browser I'm getting:
MappingException: Class 'Demo\\BusinessBundle\\Entity\\BusinessUser' does not exist
My BusinessUser Entity:
<?php
namespace Demo\BusinessBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* @ORM\Entity
* @ORM\Table(name="business_users")
*/
class BusinessUser extends BaseUser
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
*/
protected $surname;
public function __construct()
{
parent::__construct();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set surname
*
* @param string $surname
* @return BusinessUser
*/
public function setSurname($surname)
{
$this->surname = $surname;
return $this;
}
/**
* Get surname
*
* @return string
*/
public function getSurname()
{
return $this->surname;
}
}
I think it has something to do with the app/config.yml
file. Because when I change the entity name provided in user_class:
I get the same error with the class name I changed it to.
That part from config.yml
:
# FOSUserBundle configuration
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Demo\BusinessBundle\Entity\BusinessUser
Doctrine block in config.yml
:
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
The result of running php app/console doctrine:mapping:info
:
Found 3 mapped entities:
[OK] Demo\BusinessBundle\Entity\BusinessUser
[OK] FOS\UserBundle\Model\User
[OK] FOS\UserBundle\Model\Group
Edit 1: I copied the same project and tried it on Windows 8.1 and it works just fine. but on Ubuntu 14.04 LTS it doesn't.
Try to set auto_mapping: false
# app/config/config_dev.php
doctrine:
orm:
auto_mapping: false
mapping:
BusinessBundle: ~
or AppBundle
instead of BusinessBundle
I just lost 3 hours debugging this issue. I hope I save somebody's time. In some rare cases your composer autoloade might be playing games with you. Try to execute composer dumpautoload
, clear your cache /var/cache/*/
and then try again. I had the exact same problem - the entity was with the correct namespace, it was being mapped, but symfony wasn't able to find it.
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.