Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 2使用外键获取数据会返回未定义的索引_Symfony_Foreign Keys_Undefined Index - Fatal编程技术网

Symfony 2使用外键获取数据会返回未定义的索引

Symfony 2使用外键获取数据会返回未定义的索引,symfony,foreign-keys,undefined-index,Symfony,Foreign Keys,Undefined Index,我有3个实体:User、UserRole、UserProfile。 userprofile实体的主键实际上是来自用户实体的外键,即用户ID。 每次我尝试使用外键userid访问userProfile时。我总是收到一个未定义用户ID索引的错误。 这就是确切的错误消息 **>注意:中未定义的索引:userID C:\wamp\www\SymfonyFolder\vendor\doctrine\orm\lib\doctrine\orm\UnitOfWork.php 第2583行** 控制器 .....

我有3个实体:User、UserRole、UserProfile。 userprofile实体的主键实际上是来自用户实体的外键,即用户ID。 每次我尝试使用外键userid访问userProfile时。我总是收到一个未定义用户ID索引的错误。

这就是确切的错误消息

**>注意:中未定义的索引:userID

C:\wamp\www\SymfonyFolder\vendor\doctrine\orm\lib\doctrine\orm\UnitOfWork.php 第2583行**

控制器 .....

User.orm.yml

type:  entity
  table: reg_user
  oneToOne:
  id:
    userID:
      column: user_id
      type: integer
      generator: { strategy: AUTO }
      targetEntity: UserProfile
      mappedBy: userProfileID
UserProfile.orm.yml

type:  entity
  table: users_profile
  id:
    userProfileID:
      associationKey: true
  fields:
    firstName:
      column: first_name
      type: string
      length: 255
      unique: true
      nullable: false
    lastName:
      column: last_name
      type: string
      length: 255
      nullable: false
 oneToOne:
    userProfileID:
      targetEntity: User
      inversedBy: userID
      joinColumn:
        name: fk_user_id
        referencedColumnName: user_id
User.php

class User implements AdvancedUserInterface, \Serializable
{

// @var auto integer
protected $userID;

// @var string
protected $userName;

// @var string
protected $salt;

// @var string - must not persist to DB
protected $plainPassword;

// @var string
protected $password;

// @var string
protected $email;

// @var boolean
protected $isActive;

// @var string
protected $confirmationCode;

// @var datetime
protected $createdAt;

// @var string - must not persist to DB
protected $chooseRole;

// @var for roles fk_role_id - mapped
protected $userRole;


/* _construct() is an instant instance of the entity*/

public function __construct()
{
    date_default_timezone_set('Asia/Manila');
    $this->createdAt = new \DateTime("now");

//all users are inactive upon registration.
//isActive turns 'true' with the use of email confirmation
    $this->isActive = false; 
}

public function __toString()
{
    return strval($this->userID);
}

/**
 * Get userID
 *
 * @return integer 
 */
public function getUserID()
{
    return $this->userID;
}

/**
 * Set userName
 *
 * @param string $userName
 * @return User
 */
public function setUserName($userName)
{
    $this->userName = $userName;

    return $this;
}

/**
 * Get userName
 *
 * @return string 
 */
public function getUserName()
{
    return $this->userName;
}

/**
 * Set salt
 *
 * @param string $salt
 * @return User
 */
public function setSalt($salt)
{
    $this->salt = $salt;

    return $this;
}

/**
 * Get salt
 *
 * @return string 
 */
public function getSalt()
{
    return $this->salt;
}


public function setPlainPassword($plainPassword)
{
    $this->plainPassword = $plainPassword;

    return $this;
}

public function getPlainPassword()
{
    return $this->plainPassword;
}

/**
 * Set password
 *
 * @param string $password
 * @return User
 */
public function setPassword($password)
{
    $this->password = $password;

    return $this;
}

/**
 * Get password
 *
 * @return string 
 */
public function getPassword()
{
    return $this->password;
}

/**
 * Set email
 *
 * @param string $email
 * @return User
 */
public function setEmail($email)
{
    $this->email = $email;

    return $this;
}

/**
 * Get email
 *
 * @return string 
 */
public function getEmail()
{
    return $this->email;
}

/**
 * Set isActive
 *
 * @param boolean $isActive
 * @return User
 */
public function setIsActive($isActive)
{
    $this->isActive = $isActive;

    return $this;
}

/**
 * Get isActive
 *
 * @return boolean 
 */
public function getIsActive()
{
    return $this->isActive;
}

/**
 * Set confirmationCode
 *
 * @param string $confirmationCode
 * @return User
 */
public function setConfirmationCode($confirmationCode)
{
    $this->confirmationCode = $confirmationCode;

    return $this;
}

/**
 * Get confirmationCode
 *
 * @return string 
 */
public function getConfirmationCode()
{
    return $this->confirmationCode;
}

/**
 * Set createdAt
 *
 * @param \DateTime $createdAt
 * @return User
 */
public function setCreatedAt($createdAt)
{
    $this->createdAt = $createdAt;

    return $this;
}

/**
 * Get createdAt
 *
 * @return \DateTime 
 */
public function getCreatedAt()
{
    return $this->createdAt;
}

public function setChooseRole($chooseRole)
{
    $this->chooseRole = $chooseRole;

    return $this;
}

public function getChooseRole()
{
    return $this->chooseRole;
}

/**
 * Set userRole
 *
 * @param CloudPod\UserBundle\Entity\UserRoles $userRole
 * @return User
 */
public function setUserRole(\CloudPod\UserBundle\Entity\UserRoles $userRole = null)
{
    $this->userRole = $userRole;

    return $this;
}

/**
 * Get userRole
 *
 * @return CloudPod\UserBundle\Entity\UserRoles 
 */
public function getUserRole()
{
    return $this->userRole;
}


/**
 * @see \Serializable::serialize()
 */
public function serialize()
{
    return serialize(array(
        $this->userID,
    ));
}

/**
 * @see \Serializable::unserialize()
 */
public function unserialize($serialized)
{
    list (
        $this->userID,
    ) = unserialize($serialized);
}

public function isAccountNonExpired()
{ return true; }

public function isAccountNonLocked()
{ return true; }

public function isCredentialsNonExpired()
{ return true; }

public function isEnabled()
{ return $this->isActive; }

   /**
 * @inheritDoc
 */
public function eraseCredentials()
{
}

public function getRoles()
{
  return array($this->userRole);  
}
}

我想问题出在我的控制器代码上。谁能告诉我正确的编码方法吗。
P.S我将用户对用户的配置文件分开,因为我不想在表中混淆用户帐户数据(如用户名、角色等)及其用户信息。

用户实体是什么样子的?请尝试
findByUserId($id)
,因为您在orm中指定了一列。那么有些东西不起作用了吗?毕竟这只是一个通知。。。可能UnitOfWork.php中的ORM类可能没有检查数组键…@madflow唯一的问题是,我似乎无法使用其主键userID(基于用户表上的userID的外键)获取userProfile表的列行。
class User implements AdvancedUserInterface, \Serializable
{

// @var auto integer
protected $userID;

// @var string
protected $userName;

// @var string
protected $salt;

// @var string - must not persist to DB
protected $plainPassword;

// @var string
protected $password;

// @var string
protected $email;

// @var boolean
protected $isActive;

// @var string
protected $confirmationCode;

// @var datetime
protected $createdAt;

// @var string - must not persist to DB
protected $chooseRole;

// @var for roles fk_role_id - mapped
protected $userRole;


/* _construct() is an instant instance of the entity*/

public function __construct()
{
    date_default_timezone_set('Asia/Manila');
    $this->createdAt = new \DateTime("now");

//all users are inactive upon registration.
//isActive turns 'true' with the use of email confirmation
    $this->isActive = false; 
}

public function __toString()
{
    return strval($this->userID);
}

/**
 * Get userID
 *
 * @return integer 
 */
public function getUserID()
{
    return $this->userID;
}

/**
 * Set userName
 *
 * @param string $userName
 * @return User
 */
public function setUserName($userName)
{
    $this->userName = $userName;

    return $this;
}

/**
 * Get userName
 *
 * @return string 
 */
public function getUserName()
{
    return $this->userName;
}

/**
 * Set salt
 *
 * @param string $salt
 * @return User
 */
public function setSalt($salt)
{
    $this->salt = $salt;

    return $this;
}

/**
 * Get salt
 *
 * @return string 
 */
public function getSalt()
{
    return $this->salt;
}


public function setPlainPassword($plainPassword)
{
    $this->plainPassword = $plainPassword;

    return $this;
}

public function getPlainPassword()
{
    return $this->plainPassword;
}

/**
 * Set password
 *
 * @param string $password
 * @return User
 */
public function setPassword($password)
{
    $this->password = $password;

    return $this;
}

/**
 * Get password
 *
 * @return string 
 */
public function getPassword()
{
    return $this->password;
}

/**
 * Set email
 *
 * @param string $email
 * @return User
 */
public function setEmail($email)
{
    $this->email = $email;

    return $this;
}

/**
 * Get email
 *
 * @return string 
 */
public function getEmail()
{
    return $this->email;
}

/**
 * Set isActive
 *
 * @param boolean $isActive
 * @return User
 */
public function setIsActive($isActive)
{
    $this->isActive = $isActive;

    return $this;
}

/**
 * Get isActive
 *
 * @return boolean 
 */
public function getIsActive()
{
    return $this->isActive;
}

/**
 * Set confirmationCode
 *
 * @param string $confirmationCode
 * @return User
 */
public function setConfirmationCode($confirmationCode)
{
    $this->confirmationCode = $confirmationCode;

    return $this;
}

/**
 * Get confirmationCode
 *
 * @return string 
 */
public function getConfirmationCode()
{
    return $this->confirmationCode;
}

/**
 * Set createdAt
 *
 * @param \DateTime $createdAt
 * @return User
 */
public function setCreatedAt($createdAt)
{
    $this->createdAt = $createdAt;

    return $this;
}

/**
 * Get createdAt
 *
 * @return \DateTime 
 */
public function getCreatedAt()
{
    return $this->createdAt;
}

public function setChooseRole($chooseRole)
{
    $this->chooseRole = $chooseRole;

    return $this;
}

public function getChooseRole()
{
    return $this->chooseRole;
}

/**
 * Set userRole
 *
 * @param CloudPod\UserBundle\Entity\UserRoles $userRole
 * @return User
 */
public function setUserRole(\CloudPod\UserBundle\Entity\UserRoles $userRole = null)
{
    $this->userRole = $userRole;

    return $this;
}

/**
 * Get userRole
 *
 * @return CloudPod\UserBundle\Entity\UserRoles 
 */
public function getUserRole()
{
    return $this->userRole;
}


/**
 * @see \Serializable::serialize()
 */
public function serialize()
{
    return serialize(array(
        $this->userID,
    ));
}

/**
 * @see \Serializable::unserialize()
 */
public function unserialize($serialized)
{
    list (
        $this->userID,
    ) = unserialize($serialized);
}

public function isAccountNonExpired()
{ return true; }

public function isAccountNonLocked()
{ return true; }

public function isCredentialsNonExpired()
{ return true; }

public function isEnabled()
{ return $this->isActive; }

   /**
 * @inheritDoc
 */
public function eraseCredentials()
{
}

public function getRoles()
{
  return array($this->userRole);  
}