I cannot get the FOS User Bundle to work in Symfony 2.5. It's probably so simple I'm overlooking something basic. I've used this bundle before without issues and cannot find a solution online. I have everything set up and can't clear the cache -- I get this error. It also displays the error on the browser. Please be advised I am only a few weeks into learning Symfony! I followed these instructions to the letter.
Here is the error I receive:
InvalidConfigurationException: Unrecognized options "0, 1, 2" under
"fos_user"
What are the options "0, 1, 2" it is referring to? I thought maybe it was a routing issue, failing to bring in a query variable but I'm not sure.
Here is the relative part of config.yml:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
fos_user:
- db_driver: orm
- firewall_name: main
- user_class: Main\Bundle\ToolsBundle\Entity\User
Yes, it's registered in the AppKernel.php:
new FOS\UserBundle\FOSUserBundle(),
User.orm.yml:
# Main/Bundle/ToolsBundle/Resources/config/doctrine/User.orm.yml
Main\Bundle\ToolsBundle\Entity\User:
type: entity
table: fos_user
id:
id:
type: integer
generator:
strategy: AUTO
The User.php entity is straight from the demo:
// Main/Bundle/ToolsBundle/Entity/User.php
namespace Main\Bundle\ToolsBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
Remove - from fos_user config(config.yml). It should look like this:
fos_user:
db_driver: orm
firewall_name: main
user_class: Main\Bundle\ToolsBundle\Entity\User
Related
I'm using FOSUser bundle and everything went ok until I tried to create the database entities, I get this error:
It has nothing to do with the bug in Symfony 2.5, I'm using version 2.7
Case mismatch between loaded and declared class names: App\UserBundle\Entity\user vs App\UserBundle\Entity\User
This is my config file for fos:
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: App\UserBundle\Entity\User
My classes and namespaces they seem to have the right caps, I don't know why this is happening. I tried to clear the cache, no errors but didn't work.
The user class is App/UserBundle/Entity/User.php, here's the content:
<?php
namespace App\UserBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
/**
* User
*/
class User extends BaseUser
{
public function __construct()
{
parent::__construct();
}
}
What happens if you amend your User entity to appear as below (replacing user_table with intended table name)?
namespace App\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
/**
* User
* #ORM\Table(name="user_table")
* #ORM\Entity
*/
class User extends BaseUser
{
public function __construct()
{
parent::__construct();
}
}
I found the problem, I was using yaml for the entity definition and the filename was user.orm.yml instead of User.orm.yml.
I want to expose only a few properties of my User class, using JMSSerializerBundle and FOSRestBundle.
It seems like the serializer bundle is not reading my configuration file.
My User class is in src/AppBundle/Entity/User and it extends the FOSUserBundle user class.
Here is my User class:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User as BaseUser;
use Symfony\Component\Validator\Constraints as Assert;
/**
* User
*
* #ORM\Table(name="backoffice_user")
* #ORM\Entity(repositoryClass="AppBundle\Entity\Repository\UserRepository")
*/
class User extends BaseUser
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="lastname", type="string", length=70)
*/
private $lastname;
/**
* #var string
*
* #ORM\Column(name="firstname", type="string", length=70)
*/
private $firstname;
}
This is my app/config.yml file
jms_serializer:
metadata:
debug: true
auto_detection: true
And the yml mappgin file in src/AppBundle/Resources/config/serializer/Entity.User.yml :
AppBundle\Entity\User:
exclusion_policy: ALL
exclude: true
properties:
email:
exclude: true
expose: true
The file is not read (or at least not taken into account), because my API returns me all fields of my entity.
Am I forgetting something ?
Your mapping file is not loaded, because the serializer applies the rules to the class where the properties are defined. In your case - that is FOS\UserBundle\Model\User. What you need is to override the Third-Party Metadata - a brief sample can be seen in bundle's documentation
In your config.yml, jms_serializer should probably look like this:
jms_serializer:
metadata:
auto_detection: true
directories:
FOSUserBundle:
namespace_prefix: "FOS\\UserBundle"
path: "#AppBundle/Resources/config/serializer"
Inside directory serializer you should have a file named Model.User.yml with configuration like this:
FOS\UserBundle\Model\User:
exclusion_policy: ALL
# add your desired configuration below.
In JMSSerializer you need to have one file for each class of the hierarchy.
So, the exclusion policy only apply to properties id, lastname and firstname; for BaseUser it use the default rule, which is to include everything.
To override a configuration file from another bundle, you first need to setup the folder for the namespace in the configuration with:
jms_serializer:
metadata:
directories:
FOSUB:
namespace_prefix: "FOS\\UserBundle"
path: "%kernel.root_dir%/serializer/FOSUB"
And add the serializer config file in app/serializer/FOSUB/Model.User.yml. See the official docs for other configurations option.
this my entity class
<?php
namespace Application\MainAppBundleBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Oryzone\Bundle\MediaStorageBundle\Entity\Media as BaseMedia;
/**
Application\MainAppBundleBundle\Entity\Media *
#ORM\Table(name="media")
#ORM\Entity() */
class Media extends BaseMedia
{
/**
* #ORM\Id
* #ORM\Column(name="id", type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* {#inheritDoc}
*/
public function getId()
{
return $this->id;
}
}
?>
when i execute "php app/console doctrine:update:schema --force" i get this message
nothing to update ...
help please
Resolved ✔
the problem: when I execute doctrine:schema:update, the update of the data base is based on the files in # MyBundle / Resources / config / doctrine / MyFiles.orm.yml since I created my entity Entity / media.php and I have not Media.orm.yml the media table will not be created, so I deleted all files * orm.yml and I execute php app / console doctrine.: schema: update and the table is created
#hourss2040
I think you can't combine .orm.yml and annotations in same Entity.
Try to switch auto mapping on like this:
doctrine:
orm:
auto_mapping: true
Or register your bundle mapping like this:
doctrine:
orm:
entity_managers:
default:
connection: default
mappings:
MainAppBundleBundle: ~
I want to add an address and telephone number using FOSUserBundle. How can I add a Custom fields, with FOSuserBundle, to have a profile that contains address and telephone number....
Create an own user bundle and in the MyCompanyUserBundle.php you set
public function getParent(){
return 'FOSUserBundle';
}
Then in your new UserBundle you create a User entity and let it extend from the base user of the FOS user bundle:
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="user")
*/
class User extends BaseUser
{
public function __toString(){
return $this->firstname . ' ' . $this->lastname . ' (' . $this->email . ')';
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
EDIT
Set the user in the config as well:
fos_user:
db_driver: orm
firewall_name: main
user_class: MyCompany\UserBundle\Entity\User
the problem is in :
when i follow the symfony documentation:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md in step a) Doctrine ORM User class
i have created a folder doctrine contains User.orm.yml:
src/Acme/UserBundle/Resources/config/doctrine/User.orm.yml
Acme\UserBundle\Entity\User:
type: entity
table: fos_user
id:
id:
type: integer
generator:
strategy: AUTO
this file crush any update in your entities and update of your database shemea .The solution is to delete this folder.
You don't have to add custom fields but you have to create your own user model.
Read the doc, all is explained:
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/index.md#step-3-create-your-user-class
I want to extend default user entity attributes. In database after extending FOSUserBundle with SonataUserBunle there are 2 tables for storing users: fos_user and fos_user_user. I want to extend fos_user
Here is app/AppKernel.php:
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new Application\Sonata\UserBundle\ApplicationSonataUserBundle(),
in app/config.yml file I set:
fos_user:
db_driver: orm<br>
firewall_name: main<br>
user_class: Acme\DemoBundle\Entity\User<br>
group:<br>
group_class: Application\Sonata\UserBundle\Entity\Group<br>
sonata_user:
security_acl: true
class:
user: Acme\DemoBundle\Entity\User
admin:
user:
class: Acme\DemoBundle\Admin\UserAdmin
parameters:
sonata.user.admin.user.class: Blogger\BlogBundle\Admin\UserAdmin
sonata.user.admin.user.entity: Blogger\BlogBundle\Entity\User
doctrine:
orm:
auto_mapping: auto
SonataUserBundle is created in src/Application/Sonata/UserBundle
To override SonataUserBundle, i extended UserAdmin by creating another UserAdmin class in src/Acme/DemoBundle/Admin/UserAdmin and all works fine
Now I want to extend User entity (fos_user table) to add new attributes.
Here is my Acme/Demo/Entity/User.php that I want to extend the default User entity
namespace Acme\DemoBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/*
* #ORM\Column(type="string", name="newAttribute")
*/
protected $newAttribute;
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
}
What should I do to extend default fos_user table with php app/console doctrine:generate:entities Acme/DemoBundle
I've read many posts about this issue but none of the solutions helped me. I tried to extend Model class instead of Entity class but also nothing changed
You don't have to.
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle')
Here your are telling the SonataUserBundle to use the FOSUserBundle as well.
Then in your User entity you set:
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="User")
*/
class User extends BaseUser
Because you have said to the SonataUserBundle "use the fosuserbundle" and you extend from the sonata user bundle user entity he's gonna "merge" those 2 models into 1 and add your custom fields from in your user entity as well.