2015-10-20 71 views
2

我想要做我自己的认证类。symfony属性期望一个整数,但得到字符串错误

这是我的用户实体。

<?php 
namespace AppBundle\Entity; 

use Symfony\Component\Security\Core\User\UserInterface; 
use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity 
*/ 
class User 
{ 
    /** 
    * @ORM\Column(type="int", length="11") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="string", length="25") 
    */ 
    protected $login; 

    /** 
    * @ORM\Column(type="string", length="25") 
    */ 
    protected $password; 

    /** 
    * @ORM\Column(type="string", length="25") 
    */ 
    protected $firstName; 

    /** 
    * @ORM\Column(type="string", length="25") 
    */ 
    protected $lastName; 

    /** 
    * @ORM\Column(type="string", length="25") 
    */ 
    protected $email; 

    public function getId() 
    { 
    return $this->id; 
    } 

    public function getLogin() 
    { 
    return $this->login; 
    } 

    public function getPassword() 
    { 
    return $this->password; 
    } 

    public function getFirstName() 
    { 
    return $this->firstName; 
    } 

    public function getLastName() 
    { 
    return $this->lastName; 
    } 

    public function getEmail() 
    { 
    return $this->email; 
    } 

    public function setLogin($login) 
    { 
    $this->login = $login; 
    } 

    public function setPassword($password) 
    { 
    $this->password = $password; 
    } 

    public function setFirstName($firstName) 
    { 
    $this->firstName = $firstName; 
    } 

    public function setLastName($lastName) 
    { 
    $this->lastName = $lastName; 
    } 

    public function setEmail($email) 
    { 
    $this->email = $email; 
    } 
} 

而且安全设置(就像在文档)

security: 
    encoders: 
     AppBundle\Entity\User: 
      algorithm: sha512 
      encode-as-base64: true 
      iterations: 10 

    providers: 
     main: 
      entity: { class: AppBundle:User, property: login } 

    firewalls: 
     main: 
      pattern: /.* 
      form_login: 
       check_path: /account/check 
       login_path: /account/login 
      logout: true 
      security: true 
      anonymous: true 

    access_control: 
     - { path: /admin/.*, role: ROLE_ADMIN } 
     - { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY } 

我得到一个错误 - [类型错误]物业的appbundle \实体\宣布@ORM \列的属性 “长度” User :: $ id需要一个(n)整数,但得到了字符串。

林不知道我能理解错误。从哪里得到字符串?我甚至没有任何东西在用户表中。

我想请你帮我解决这个问题。

谢谢

回答

5

您通过将它用引号引起来传递给它一个字符串。我怀疑你认为这是类似于HTML,你需要放在引号的属性 - 这是不是这里的情况:

class User 
{ 
    /** 
    * @ORM\Column(type="int", length=11) 
    */ 
    protected $id; 

//... 
} 

应用您使用length="11"

+0

删除引号。问题没有解决 –

0

如果我这个改变一切m没有错误的类型应该是整数,你不需要长度。所以像

/** 
* @ORM\Column(type="integer") 
*/ 
protected $id; 
相关问题