我有问题。我创建了两个与关联的实体。
实体代码:
/** @entity
* @table(name="mt_employee")
*/
class EmployeeEntity{
/**
* @id @column(type="integer")
* @generatedValue
*/
private $id_employee;
/**
* @column(length=100)
*/
private $login;
/**
* @column(length=300)
*/
private $password;
/**
* @column(length=50)
*/
private $name;
/**
* @column(length=50)
*/
private $surname;
/**
* @column(length=50)
*/
private $email;
/**
* @column(type="smallint")
*/
private $remote_login;
/**
* @column(length=100)
*/
private $hash;
/**
* @oneToMany(targetEntity="EmployeeShopEntity", mappedBy="employee")
* @joinColumn(name="id_employee", referencedColumnName="id_employee")
*/
private $employeeShop;
public function getIdEmployee(){
return $this->getIdEmployee();
}
public function getLogin(){
return $this->login;
}
public function getPassword(){
return $this->password;
}
public function getName(){
return $this->name;
}
public function getSurname(){
return $this->surname;
}
public function getEmail(){
return $this->email;
}
public function getRemoteLogin(){
return $this->remote_login;
}
public function getHash(){
return $this->hash;
}
public function setLogin($login){
$this->login = $login;
}
public function setPassword($password){
$this->password = $password;
}
public function setName($name){
$this->name = $name;
}
public function setSurname($surname){
$this->surname = $surname;
}
public function setEmail($email){
$this->email = $email;
}
public function setRemoteLogin($remote_login){
$this->remote_login = $remote_login;
}
public function setHash($hash){
$this->hash = $hash;
}
public function employeeShop(){
return $this->employeeShop;
}
public function getIdShop(){
return $this->employeeShop->getIdShop();
}
}
/** @entity
* @table(name="mt_employee_shop")
*/
class EmployeeShopEntity{
/**
* @id @column(type="integer")
* @generatedValue
*/
private $id_employee_shop;
/**
* @column(type="integer")
*/
private $id_employee;
/**
* @column(type="integer")
*/
private $id_shop;
/**
* @manyToOne(targetEntity="EmployeeEntity", inversedBy="employeeShop")
* @joinColumn(name="id_employee", referencedColumnName="id_employee")
*/
private $employee;
public function getIdShop(){
return $this->id_shop;
}
}
获取数据:
$query = Context::getContext()->entity_manager->createQuery('SELECT e FROM EmployeeEntity e JOIN e.employeeShop es WHERE e.login = ?1 AND e.password = ?2')->setParameter(1,$login)->setParameter(2,md5($password));
$employee = $query->getResult(2);
$employee = $employee[0];
if($employee){
foreach($employee AS $key=>$em){
$this->{$key} = $em;
}
$employee_shop = $query->getResult();
$employee_shop = $employee_shop[0];
print_r($employee_shop->employeeShop()->getIdShop());
}
当我尝试访问$ lighteree_shop-> lomyeeeshop() -> getIdShop()时,我收到了错误消息:
致命错误:致电未定义的方法学说 orm persistentCollection :: getIdShop()在/../class/employee.class.php上,第27行27
我该如何修复?
谢谢
" $ lighteree_shop-> lospereeShop()" - 这是 Collection 。
使用" for"因此,请尝试使用" $ obj-> getIdShop()"打印ID。