Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOS UserBundle Unable to login

I'm back with another issue regarding my UserBundle : Everything went perfect while installing and configuring FOS bundle through Symfony2, it even let me create 2 users that were properly inserted into my DB.

However, every time I try to login into either of these accounts, I get the following error

Warning: Erroneous data format for unserializing 'VillaPrivee\UserBundle\Entity\User' in /Users/Vianney/Projets/VillaPrivee/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 869

This is what the line 869 refers to :

/**
     * Creates a new instance of the mapped class, without invoking the constructor.
     *
     * @return object
     */
    public function newInstance()
    {
        if ($this->_prototype === null) {
            $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        }

        return clone $this->_prototype;
    }

And this is my User entity :

namespace VillaPrivee\UserBundle\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
    }
}

Not sure what I did wrong, since I just installed the whole thing following the step by step documentation... Thanks guys for your help

like image 321
wattever Avatar asked Jun 04 '14 07:06

wattever


2 Answers

If you are using PHP Version 5.4.29 or 5.5.13

In: "/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php" find function "newInstance" (around Line 827) and edit as followed until the Fix is merged by doctrine.

public function newInstance()
{
    if ($this->_prototype === null) {
        // $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
            $this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
        } else {
            $this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
        }
    }
    return clone $this->_prototype;
}

@Benji: thx for the hint: https://github.com/symfony/symfony/issues/11056

like image 76
grow Avatar answered Nov 10 '22 17:11

grow


Answering my own question, I found a workaround thanks to this guy :

http://www.doctrine-project.org/jira/browse/DDC-3120

He's far better than me when it comes to explaining, but this is what I have now, and it works like a charm! :)

{
        if ($this->_prototype === null) {
            $this->_prototype = @unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
            if ($this->_prototype === false) {
                $this->_prototype = @unserialize(sprintf('C:%d:"%s":0:{}', strlen($this->name), $this->name));
            }
        }

        return clone $this->_prototype;
    }
like image 18
wattever Avatar answered Nov 10 '22 16:11

wattever