我正在尝试在我的实体类中编写新的 get 方法
这是楼盘
protected $courseLink;
它的get方法
/**
* Get courseLink
*
* @return string
*/
public function getCourseLink()
{
$this->courseLink = '/courses/'.$this->getCourseTitle();
return $this->courseLink;
}
getCourseTitle 方法
/**
* Get courseTitle
*
* @return string
*/
public function getCourseTitle()
{
return $this->courseTitle;
}
这是带有选择查询的控制器
$em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery(
'SELECT c FROM DprocMainBundle:Courses c ORDER BY c.Id DESC'
);
$course = $query->setMaxResults(4)->getResult();
//print_r($course);
return $this->render('DprocMainBundle:Dproc:index.html.twig', array('courses' => $course));
print_r 显示
大批
(
[0] => Dproc\MainBundle\Entity\Courses Object
(
[Id:protected] => 1
[courseTitle:protected] => 3ds Max и Vray
[courseContent:protected] => 3ds max course is awesome!
[courseCategory:protected] => 3ds-max
[courseTeacher:protected] => Ваге Мурадян
[coursePayment:protected] => payment..
[courseSchedule:protected] => schedule..
[courseDescription:protected] => description..
[courseLink:protected] =>
)
)
courseLink 为空,但为什么呢?那么我应该如何在课堂上赋予它价值呢?