Symfony属性期望一个整数,但得到字符串错误


Symfony attribute expects a integer, but got string error

我想做我自己的身份验证类。

这是我的User实体。

<?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 }

我得到下一个错误-[类型错误]属性"长度"的@ORM'列上声明的属性AppBundle'Entity'User::$id期望一个(n)整数,但得到字符串。

我不确定我能理解这个错误。它从哪里得到的绳子?我甚至没有任何东西在users表

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

谢谢

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

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

应用此更改所有您使用的length="11"

如果我没有错,类型应该是整数,你不需要长度。比如

/**
 * @ORM'Column(type="integer")
 */
protected $id;