我有一个关于 Symfony 应用程序的问题,我想输入我的控制器的“用户名”或“id”,并接收我的表“用户”和其他 2 个表中的信息,例如:一个用户有一个或更多级别,而且它有积分必须赚取积分才能解锁一个级别,我希望我的 dan 主页显示用户名和它的级别和程度,我是初学者,不了解我使用的书籍 symfony ,我使用 PARALLEL“symfony_book”和“symfony_cook_book”以及教程 youtube 我可以阻止,这是我的 cotroler 的代码“
/**
* @Route("/{id}")
* @Template()
* @param $id=0
* @return array
*/
public function getUserAction($id)
{
$username = $this->getDoctrine()
->getRepository('voltaireGeneralBundle:FosUser')
->find($id);
if (!$username) {
throw $this->createNotFoundException('No user found for id '.$id);
}
//return ['id' => $id,'username' => $username];
return array('username' => $username);
}
我必须使用类之间的关系
use Doctrine\Common\Collections\ArrayCollection;
class Experience {
/**
* @ORM\OneToMany(targetEntity="FosUser", mappedBy="experience")
*/
protected $fosUsers;
public function __construct()
{
$this->fosUsers = new ArrayCollection();
}
}
和
class FosUser {
/**
* @ORM\ManyToOne(targetEntity="Experience", inversedBy="fosUsers")
* @ORM\JoinColumn(name="experience_id", referencedColumnName="id")
*/
protected $fosUsers;
}
我总是有一个错误