Symfony属性需要一个整数,但是会出现字符串错误

Tig*_*yan 3 php 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;
    }
}
Run Code Online (Sandbox Code Playgroud)

和安全设置(就像在文档中一样)

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 }
Run Code Online (Sandbox Code Playgroud)

我收到下一个错误 - [类型错误]属性"长度"的@ORM \列在属性AppBundle\Entity\User :: $ id上声明需要一个(n)整数,但得到了字符串.

我不确定我能理解错误.从哪里得到字符串?我甚至在用户表中都没有任何东西.

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

谢谢

HPi*_*rce 7

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

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

//...
}
Run Code Online (Sandbox Code Playgroud)

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