2

This is the very first time I use Symfony2 by myself and I think I've made a mistake when configuring the FOS User Bundle. Looks like my User entity does not properly extend the FOS\UserBundle\Entity\User.

Here's my User class (basically the same as mentioned on the doc)

<?php // src/Acme/UserBundle/Entity/User.php namespace VillaPrivee\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; use FOS\UserBundle\Entity\User as BaseUser; /** * @ORM\Entity * @ORM\Table(name="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 } } 

Since I use Netbeans, I'm able to "Ctrl click" and make sure "FOS\UserBundle\Entity\User" exists. So far, I don't see anything wrong...

But when I try to create a new user using my terminal, I get this error:

Fatal error: Call to undefined method VillaPrivee\UserBundle\Entity\User::setUsername() in /Applications/MAMP/htdocs/VillaPrivee/vendor/friendsofsymfony/ user-bundle/FOS/UserBundle/Util/UserManipulator.php on line 50 

Not sure what other details I should provide you guys with, just let me know if any other file could matter in this case.

Thanks for your help!

Edit :

<?php namespace VillaPrivee\UserBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; class VillaPriveeUserBundle extends Bundle { public function getParent() { return 'FOSUserBundle'; } } 

config.yml:

fos_user: db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel' firewall_name: main user_class: VillaPrivee\UserBundle\Entity\User 
5
  • is FOSUserBundle registered in AppKernel.php? Commented Jun 3, 2014 at 10:39
  • Could you include AppKernel.php? Moreover, why are you extending FOSUserBundle? Are you going to manipulate FOSUserBundle controllers via override? Commented Jun 3, 2014 at 10:59
  • new FOS\UserBundle\FOSUserBundle(),new VillaPrivee\UserBundle\VillaPriveeUserBundle(), Commented Jun 3, 2014 at 11:01
  • How am I supposed to include the appKernel? All I did was just following the documentation, I'm not planning on overwriting anything for now Commented Jun 3, 2014 at 11:02
  • If you don't need to override something particular, you should remove return 'FOSUserBundle' part into getParent() method. Moreover with "include AppKernel.php" I mean if you can past it into your question :) Commented Jun 3, 2014 at 11:04

3 Answers 3

6

I think you extend wrong class, try with:

use FOS\UserBundle\Model\User as BaseUser; 

Edit:

Yep, extending FOS\UserBundle\Entity\User is deprecated, Extend FOS\UserBundle\Model\User directly. Documentation

Sign up to request clarification or add additional context in comments.

11 Comments

doesn't work either... I still get the same error :(
codepublic function create($username, $password, $email, $active, $superadmin) { $user = $this->userManager->createUser(); $user->setUsername($username); $user->setEmail($email); $user->setPlainPassword($password); $user->setEnabled((Boolean) $active); $user->setSuperAdmin((Boolean) $superadmin); $this->userManager->updateUser($user); return $user; }
@DonCallisto read this It won't be supported so it's better to use proper class. I'm still trying to help him, I don't know why did you downvoted :/
@wattever Is your VillaPrivee\UserBundle\VillaPriveeUserBundle.php class overriding getParent method?
@bartek : here is the file content: <?php namespace VillaPrivee\UserBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; class VillaPriveeUserBundle extends Bundle { }
|
0

Just in case someone gets the same issue as I did, i found out where the problem came from : I'm using a Mac but didn't want to get in trouble using the embedded PHP server. So I decided to use MAMP... Huge mistake! Everything I tried using my terminal was trying to access default PHP instead of MAMP one... Basically, I had to remove MAMP and upgrade my Mac PHP so I could use it together with Symfony. Sorry if I'm not crystal clear, but I don't really understand it all myself...

PS: For those using MAMP, don't be as stupid as I am : your project folder is stored INSIDE your MAMP application folder. So if you trash it, you'll trash all your projects at the same time... Yep, I'm still crying about it!

Comments

0

I have also encountered this issue. This video really helped me. https://knpuniversity.com/screencast/fosuserbundle-ftw

in AppKernel.php

This was my mistake:

 $bundles = array( new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new AppBundle\AppBundle(), new FOS\UserBundle\FOSUserBundle(), new \Acme\UserBundle\Entity\User() ); 

This is the problem new \Acme\UserBundle\Entity\User()

Follow the video and you will see that you need something like this

$bundles = array( new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), new Symfony\Bundle\TwigBundle\TwigBundle(), new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Symfony\Bundle\AsseticBundle\AsseticBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new AppBundle\AppBundle(), new FOS\UserBundle\FOSUserBundle(), new \Acme\UserBundle\AcmeUserBundle() ); 

Here is the AcmeUserBundle class:

// src/Acme/UserBundle/AcmeUserBundle.php namespace Acme\UserBundle; use Symfony\Component\HttpKernel\Bundle\Bundle; class AcmeUserBundle extends Bundle { } 

The UserBundle\Entity\User class is just like in the documentation

One last thing that I also saw on the view was the orm: entry in the config.yml Notice the auto_mapping: true

doctrine: dbal: driver: "%database_driver%" host: "%database_host%" port: "%database_port%" dbname: "%database_name%" user: "%database_user%" password: "%database_password%" charset: UTF8 orm: default_entity_manager: default auto_generate_proxy_classes: "%kernel.debug%" auto_mapping: true 

Hops this will help someone else

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.