0
$factory = $this->get('security.encoder_factory');
    var_dump($factory);

    $encoder = $factory->getEncoder($user);

    //$encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
    $password = $encoder->encodePassword($user->getUserPass(), $user->getUserSalt());
    $user->setUserPass($password);

错误

Catchable Fatal Error: Argument 1 passed to Symfony\Component\Security\Core\Encoder\EncoderFactory::getEncoder() must implement interface Symfony\Component\Security\Core\User\UserInterface, instance of Acme\AdminBundle\Entity\SyjUsers given, called in D:\Zend\joke\src\Acme\AdminBundle\Controller\AdminController.php on line 28 and defined in D:\Zend\joke\vendor\symfony\src\Symfony\Component\Security\Core\Encoder\EncoderFactory.php line 33

500 内部服务器错误 - ErrorException

用户实体

<?php

namespace Acme\UserBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

use Symfony\Component\Security\Core\User\UserInterface;


/**
 * Acme\UserBundle\Entity\SyjUsers
 *
 * @ORM\Table(name="syj_users")
 *
 * @ORM\Entity
 */

class SyjUsers implements UserInterface
{

    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     *
     * @ORM\Id
     *
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string $userLogin
     *
     * @ORM\Column(name="user_login", type="string", length=60, nullable=false)
     */
    private $userLogin;

    /**
     * @var string $userSalt
     *
     * @ORM\Column(name="user_salt", type="string", length=64, nullable=false)
     */
    private $userSalt;

    /**
     * @var string $userPass
     *
     * @ORM\Column(name="user_pass", type="string", length=64, nullable=false)
     */
    private $userPass;

    /**
     * @var string $userNicename
     *
     * @ORM\Column(name="user_nicename", type="string", length=60, nullable=true)
     */
    private $userNicename;

    /**
     * @var string $userEmail
     *
     * @ORM\Column(name="user_email", type="string", length=100, nullable=true)
     */
    private $userEmail;

    /**
     * @var string $userUrl
     *
     * @ORM\Column(name="user_url", type="string", length=60, nullable=true)
     */
    private $userUrl;

    /**
     * @var boolean $userStatus
     *
     * @ORM\Column(name="user_status", type="boolean", nullable=false)
     */
    private $userStatus;

    /**
     * @var string $userDisplayName
     *
     * @ORM\Column(name="user_display_name", type="string", length=60, nullable=true)
     */
    private $userDisplayName;



    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set userLogin
     *
     * @param string $userLogin
     */
    public function setUserLogin($userLogin)
    {
        $this->userLogin = $userLogin;
    }

    /**
     * Get userLogin
     *
     * @return string 
     */
    public function getUserLogin()
    {
        return $this->userLogin;
    }

    /**
     * Set userSalt
     *
     * @param string $userSalt
     */
    public function setUserSalt($userSalt)
    {
        $this->userSalt = $userSalt;
    }

    /**
     * Get userSalt
     *
     * @return string 
     */
    public function getUserSalt()
    {
        return $this->userSalt;
    }

    /**
     * Set userPass
     *
     * @param string $userPass
     */
    public function setUserPass($userPass)
    {
        $this->userPass = $userPass;
    }

    /**
     * Get userPass
     *
     * @return string 
     */
    public function getUserPass()
    {
        return $this->userPass;
    }

    /**
     * Set userNicename
     *
     * @param string $userNicename
     */
    public function setUserNicename($userNicename)
    {
        $this->userNicename = $userNicename;
    }

    /**
     * Get userNicename
     *
     * @return string 
     */
    public function getUserNicename()
    {
        return $this->userNicename;
    }

    /**
     * Set userEmail
     *
     * @param string $userEmail
     */
    public function setUserEmail($userEmail)
    {
        $this->userEmail = $userEmail;
    }

    /**
     * Get userEmail
     *
     * @return string 
     */
    public function getUserEmail()
    {
        return $this->userEmail;
    }

    /**
     * Set userUrl
     *
     * @param string $userUrl
     */
    public function setUserUrl($userUrl)
    {
        $this->userUrl = $userUrl;
    }

    /**
     * Get userUrl
     *
     * @return string 
     */
    public function getUserUrl()
    {
        return $this->userUrl;
    }

    /**
     * Set userStatus
     *
     * @param boolean $userStatus
     */
    public function setUserStatus($userStatus)
    {
        $this->userStatus = $userStatus;
    }

    /**
     * Get userStatus
     *
     * @return boolean 
     */
    public function getUserStatus()
    {
        return $this->userStatus;
    }

    /**
     * Set userDisplayName
     *
     * @param string $userDisplayName
     */
    public function setUserDisplayName($userDisplayName)
    {
        $this->userDisplayName = $userDisplayName;
    }

    /**
     * Get userDisplayName
     *
     * @return string 
     */
    public function getUserDisplayName()
    {
        return $this->userDisplayName;
    }
    /**
     * @inheritDoc
     */
    public function getUsername()
    {
        return $this->userLogin;
    }

    /**
     * @inheritDoc
     */
    public function getSalt()
    {
        return $this->userSalt;
    }

    /**
     * @inheritDoc
     */
    public function getPassword()
    {
        return $this->userPass;
    }

    /**
     * @inheritDoc
     */
    public function getRoles()
    {
        return array('ROLE_USER');
    }

    /**
     * @inheritDoc
     */
    public function eraseCredentials()
    {
    }

    /**
     * @inheritDoc
     */
    public function equals(UserInterface $user)
    {
        return $this->userLogin === $user->getUsername();
    }
}
4

1 回答 1

0

你有没有试过

implements CustomUserInterface

而不是

implements UserInterface
于 2012-09-25T06:52:09.697 回答