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

时间:2015-10-20 15:45:50

标签: 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;
    }
}

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

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)整数,但得到了字符串。

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

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

由于

2 个答案:

答案 0 :(得分:6)

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

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

//...
}

将您使用的所有内容length="11"

应用此更改

答案 1 :(得分:0)

如果我没错,那么type应该是整数,你不需要长度。像

这样的东西
     HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDefaultUseCaches(false);
    conn.setUseCaches(false);
    conn.setReadTimeout(15000);
    conn.setConnectTimeout(15000);
    conn.setRequestMethod("POST");
    conn.setDoInput(true);
    conn.setDoOutput(true);

    int responseCode = conn.getResponseCode();

    if (responseCode == HttpsURLConnection.HTTP_OK) {
        String line;
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        while ((line = br.readLine()) != null) {
            response += line;
        }
    } else {
        response = "";

    }