Symfony2를 사용하여 웹 응용 프로그램을 만들었으며 PUGX User Bundle과 FosUserBundle을 사용하여 2 명의 다른 사용자를 관리하고 있습니다.in_array()는 매개 변수 2가 배열이 될 것으로 예상합니다.
이 두 사용자 중 하나입니다
/**
* @ORM\Entity
* @ORM\Table(name="user_Operator")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(fields = "username", targetClass = "Acme\ManagementBundle\Entity\User", message="Username already_used")
* @UniqueEntity(fields = "email", targetClass = "Acme\ManagementBundle\Entity\User", message="Email already_used")
*/
class UserOperator extends User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\PrePersist
*/
public function setCreatedAtValue()
{
$this->addRole('ROLE_OPERATOR');
}
}
내가 등록하려고 할 때, 내가보기보다, 제출 양식을 작성 : 다음은
Warning: in_array() expects parameter 2 to be array, null given in C:\BitNami\wampstack-
5.4.23-0\frameworks\symfony\vendor\friendsofsymfony\user-
bundle\FOS\UserBundle\Model\User.php line 142
라인 (142)입니다 :
135 public function addRole($role)
{
$role = strtoupper($role);
if ($role === static::ROLE_DEFAULT) {
return $this;
}
142 if (!in_array($role, $this->roles, true)) {
$this->roles[] = $role;
}
return $this;
}
사용자와 임무 사이에 @ORM \ ManyToMany를 연결 한 이래로이 문제가 있기 때문에 모릅니다. 그것은 여기에 나타나지 않는 다른 엔티티입니다. 이 전에는이 문제가 없었습니다.
두 개의 다른 종류의 사용자를 쉽게 관리 할 수 있으므로 PUGXUser Bundle을 사용합니다. User Entity는 내 번들에 있으며 FosUserBundle ..../Model/User.php를 확장하며 UserOperator와 UserGroundStation에 의해 확장됩니다.
/**
* @var array
*/
protected $roles;
과 costruct은 다음과 같습니다 :
역할의 정의는 FosUserBundle .../모델/User.php에
public function __construct()
{
$this->roles = array();
}
'$ this-> roles'을 클래스에서'= array();로 초기화하십시오. –
2 명의 다른 사용자에게 2 묶음을 사용하지 않아야합니다. 예를 들어, FOSUserBundle은 사용자 관리에 대해 필요한 모든 것을 제공합니다. – Xatenev
'$ roles' 속성 정의를 보여주십시오. 이것은 단순한 배열인가 아니면 Doctrine ArrayCollection입니까? –