当我尝试从 JoinColumns 获取结果时,视图中出现错误。这是控制器中的查询
public function indexAction()
{
$users = $this->getEntityManager()
->getRepository('ApanelUsersEntityUsercommon')
->findAll();
$viewModel = new ViewModel(['users' => $users]);
return $viewModel;
}
这是实体代码的一部分
/**
* @var integer
*
* @ORMColumn(name="UserId", type="integer", precision=0, scale=0, nullable=false, unique=false)
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $userid;
/**
* @var string
*
* @ORMColumn(name="UserEmail", type="string", length=100, precision=0, scale=0, nullable=false, unique=false)
*/
private $useremail;
/**
* @var string
*
* @ORMColumn(name="UserFirstName", type="string", length=255, precision=0, scale=0, nullable=false, unique=false)
*/
private $userfirstname;
/**
* @var ApanelUsersEntityUserstatus
*
* @ORMManyToOne(targetEntity="ApanelUsersEntityUserstatus")
* @ORMJoinColumns({
* @ORMJoinColumn(name="User_StatusId", referencedColumnName="UserStatusId", nullable=false)
* })
*/
private $userStatusid;
这是我的观点
<td>
<?= $user->getUserFirstName(); ?>
</td>
<td>
<?= $user->getUserEmail(); ?>
</td>
当我尝试获取<?= $user->getUser_StatusId(); ?>
时,我遇到了一个错误:
-致命错误:调用未定义的方法 ApanelUsers\Entity\Usercommon::getUser_StatusId() 在/home/xtadmin/localhost/panorama-hotel.local/www/module/ApanelUsers/view/apanel-users/index/index.phtml 第 52 行
-|更新 |--我已经更改了由 Doctrine 生成的实体文件,所以我有:实体
/**
* @var ApanelUsersEntityUserstatus
*
* @ORMManyToOne(targetEntity="ApanelUsersEntityUserstatus")
* @ORMJoinColumns({
* @ORMJoinColumn(name="User_StatusId", referencedColumnName="UserStatusId", nullable=false)
* })
*/
private $userStatusid;
/**
* Set userStatusid
*
* @param ApanelUsersEntityUserstatus $userStatusid
* @return Usercommon
*/
public function setUserStatusid(ApanelUsersEntityUserstatus $userStatusid = null)
{
$this->userStatusid = $userStatusid;
return $this;
}
/**
* Get userStatusid
*
* @return ApanelUsersEntityUserstatus
*/
public function getUserStatusid()
{
return $this->userStatusid;
}
索引.phtml
<?= $user->getUserStatusid(); ?>
我钢有一个错误
可捕获的致命错误:类 DoctrineORMModule\Proxy__CG__\ApanelUsers\Entity\Userstatus 无法转换为第 27 行/home/xtadmin/localhost/panorama-hotel.local/www/module/ApanelUsers/view/apanel-users/index/index.phtml 中的字符串
问题是你用这个下划线调用了一个方法"getUser_StatusId()",但它是在没有它的情况下定义的 "getUserStatusId()"