1
내 사용자 엔티티에 대한 validation.yml에 정의 된 유효성 검증 제한 사항이 있지만 실제로 호출 된 것은 없습니다. 그것은 에서 일하고 있었지만 이제는 세 가지 제약 조건 중 어느 것도 검사하지 않습니다. SQL 고유의 제약 조건 오류가 발생하므로 코드에서 올바르게 처리되지 않았습니다 ( ). 여기 FOSUserBundle/Symfony2 : 사용자 엔티티에 대해 확인 제한이 전혀 적용되지 않습니다.
내 validation.yml입니다 :Acme\CPBundle\Entity\User:
constraints:
- Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: { fields: username, message: userExists }
- FOS\UserBundle\Validator\Unique: {property: usernameCanonical, message: userExists}
- Callback:
methods: [isTimeZoneValid]
properties:
firstName:
- MaxLength: 255
lastName:
- MaxLength: 255
username:
- NotBlank: { groups: [create_user] }
- MinLength: { limit: 4, groups: [create_user] }
- MaxLength: { limit: 50, groups: [create_user] }
email:
- NotBlank: { groups: [create_user, edit_user] }
- MaxLength: { limit: 255, groups: [create_user, edit_user] }
- Email:
message: The email "{{ value }}" is not a valid email
checkMX: true
plainPassword:
- NotBlank: { groups: [create_user] }
- MinLength: { limit: 6, groups: [create_user], message: "passwordMin {{ limit }}" }
newPassword:
- MinLength: { limit: 6, groups: [edit_user], message: "passwordMin {{ limit }}" }
singleRole:
- Choice: { callback: getAllowedRoles }
여기 내 사용자 기업의 : 나는 일이를 알아 내기 위해 노력했습니다
<?php
namespace Acme\CPBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\UserBundle\Model\User as BaseUser;
use Acme\CPBundle\Constant\SecurityConstant;
use Symfony\Component\Validator\ExecutionContext;
/**
* Acme\CPBundle\Entity\User
*/
class User extends BaseUser {
/**
* @var \Acme\CPBundle\Entity\Organization $organization
*/
private $organization;
/**
* @var string $firstName
*/
private $firstName;
/**
* @var string $lastName
*/
private $lastName;
/**
* @var DateTime $timeZone
*/
private $timeZone;
/**
* @var Role $singleRole
*/
private $singleRole;
/**
* @var ArrayCollection $sessions
*/
private $sessions;
/**
* @var integer $id
*/
protected $id;
public function __construct() {
parent::__construct();
$this->enabled = true;
$this->sessions = new ArrayCollection();
}
public function setFirstName($firstName) {
$this->firstName = $firstName;
}
public function getFirstName() {
return $this->firstName;
}
public function setLastName($lastName) {
$this->lastName = $lastName;
}
public function getLastName() {
return $this->lastName;
}
public function setTimeZone($timeZone) {
$this->timeZone = $timeZone;
}
public function getTimeZone() {
return $this->timeZone;
}
public function getId() {
return $this->id;
}
public function setOrganization(\Acme\CPBundle\Entity\Organization
$organization) {
$this->organization = $organization;
}
public function getOrganization() {
return $this->organization;
}
public function setSingleRole($singleRole) {
$this->singleRole = $singleRole;
}
public function getSingleRole() {
return $this->singleRole;
}
public function setSessions($sessions) {
$this->sessions = $sessions;
}
public function getSessions() {
return $this->sessions;
}
/*
* Form Validation Methods
*/
public static function getAllowedRoles() {
return array(SecurityConstant::ROLE_ADMIN,
SecurityConstant::ROLE_ORG_ADMIN, SecurityConstant::ROLE_USER);
}
public function isTimeZoneValid(ExecutionContext $context) {
$timeZoneIdentifiers = \DateTimeZone::listIdentifiers();
if (!in_array($this->getTimeZone(), $timeZoneIdentifiers)) {
$propertyPath = $context->getPropertyPath() . '.timeZone';
$context->setPropertyPath($propertyPath);
$context->addViolation('timeZoneInvalid', array(), null);
}
}
,하지만 난 전혀 조금 생각이 없다 무슨 문제일지도 몰라.
도움을 주시면 감사하겠습니다.
감사합니다, 분명히
고마워요! 내가 이것을 발견하기 전에 나는 한 시간의 검색과 시도가 필요했다. – Andrew
같은 문제가 있습니다. 이것을 validation.yml에 추가 했는가? –