致命错误:在视图中调用未定义的方法

时间:2015-04-18 21:55:57

标签: php doctrine-orm zend-framework2

当我尝试从JoinColumns获取结果时,视图中出现错误。这是控制器中的查询

public function indexAction()
{
    $users = $this->getEntityManager()
                     ->getRepository('\ApanelUsers\Entity\Usercommon')
                     ->findAll();

    $viewModel = new ViewModel(['users' => $users]);
    return $viewModel;
}

以下是实体代码的一部分

/**
 * @var integer
 *
 * @ORM\Column(name="UserId", type="integer", precision=0, scale=0, nullable=false, unique=false)
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $userid;

/**
 * @var string
 *
 * @ORM\Column(name="UserEmail", type="string", length=100, precision=0, scale=0, nullable=false, unique=false)
 */
private $useremail;

/**
 * @var string
 *
 * @ORM\Column(name="UserFirstName", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
 */
private $userfirstname;

/**
 * @var \ApanelUsers\Entity\Userstatus
 *
 * @ORM\ManyToOne(targetEntity="ApanelUsers\Entity\Userstatus")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="User_StatusId", referencedColumnName="UserStatusId", nullable=false)
 * })
 */
private $userStatusid;

这是我的观点

<td>
        <?= $user->getUserFirstName(); ?> 
    </td>
    <td>
        <?= $user->getUserEmail(); ?>
    </td>

当我尝试<?= $user->getUser_StatusId(); ?>时,我遇到了错误:

  

致命错误:在/home/xtadmin/localhost/panorama-hotel.local/www/module/ApanelUsers/view/apanel-users/index/index中调用未定义的方法ApanelUsers \ Entity \ Usercommon :: getUser_StatusId()。第52行的phtml

- |更新| - 我已经更改了Doctrine生成的Entity文件,所以我有: 实体

 /**
 * @var \ApanelUsers\Entity\Userstatus
 *
 * @ORM\ManyToOne(targetEntity="ApanelUsers\Entity\Userstatus")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="User_StatusId", referencedColumnName="UserStatusId", nullable=false)
 * })
 */
private $userStatusid;

 /**
 * Set userStatusid
 *
 * @param \ApanelUsers\Entity\Userstatus $userStatusid
 * @return Usercommon
 */
public function setUserStatusid(\ApanelUsers\Entity\Userstatus $userStatusid = null)
{
    $this->userStatusid = $userStatusid;

    return $this;
}

/**
 * Get userStatusid
 *
 * @return \ApanelUsers\Entity\Userstatus 
 */
public function getUserStatusid()
{
    return $this->userStatusid;
}

index.phtml

<?= $user->getUserStatusid(); ?>

我钢铁有错误

  

捕获致命错误:类/ DoctrineORMModule \ Proxy__CG __ \ ApanelUsers \ Entity \ Userstatus类的对象无法转换为/home/xtadmin/localhost/panorama-hotel.local/www/module/ApanelUsers/view/apanel-users中的字符串第27行/index/index.phtml

1 个答案:

答案 0 :(得分:0)

问题是你用这个下划线调用了一个方法“getUser_StatusId()”,但它是在没有它的情况下定义的“getUserStatusId()”