Reputation: 512
I am trying to do my own authentication class.
Here is my User entity.
<?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;
}
}
And the security settings (just like in docs)
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 }
I am getting next error - [Type Error] Attribute "length" of @ORM\Column declared on property AppBundle\Entity\User::$id expects a(n) integer, but got string.
Im not sure i can understand the error. From where it got string? I dont even have anything in users table.
I would like to ask you to help me to solve this.
Thanks
Upvotes: 3
Views: 3440
Reputation: 3
If I'm not wrong type should be integer and you don't need the length. So something like
/**
* @ORM\Column(type="integer")
*/
protected $id;
Upvotes: 0
Reputation: 7409
You're passing it a string by enclosing it in quotes. I'm suspect you think it's similar to HTML where you do need to enclose attributes in quotes - that is not the case here:
class User
{
/**
* @ORM\Column(type="int", length=11)
*/
protected $id;
//...
}
Apply this change everything you used length="11"
Upvotes: 9