데이터베이스의 데이터를 표시하려고합니다.Symfony와 Doctrine - 데이터베이스의 데이터 표시
pages:
pattern: /pages/{id}
defaults:
_controller: DprocMainBundle:Index:show
이 그 경로에 대한 방법입니다 :
public function showAction($id)
{
$page = $this->getDoctrine()
->getRepository('DprocMainBundle:Pages')
->find($id);
if (!$page) {
throw $this->createNotFoundException('No product found for id '.$id);
}
return $this->render('DprocMainBundle:Dproc:single.html.twig',array('pages' => $page));
}
인 print_r ($ 페이지) 디스플레이 : single.html에서
Dproc\MainBundle\Entity\Pages Object
(
[Id:protected] => 1
[page_title:protected] => A Foo Bar
[page_content:protected] => Test content for page
[page_category:protected] => 3dsmax
)
이 내 라우팅입니다. 그 정보를 표시하려고하는 나뭇 가지.
{% for page in pages %}
{{ page.page_title }}
{% endfor %}
아무 것도 보여주지 않습니다. 내가 뭘 잘못하고있는 걸까요?
하나의 결과를 반복 할 수 있습니까? 'for'가없는 {{pages.page_title}}을 왜 보지 않으시겠습니까? – apoq
물론 - "Dproc \ MainBundle \ Entity \ Pages"개체에 대한 메서드 "page_title"이 DprocMainBundle에 존재하지 않습니다. Dproc : single.html.twig –
getter 메서드 {{page.getPageTitle}}로 수행했습니다. –