문제

I make a controller action in which I used doctrine query for getting result but when I view result it show null.how I set the query of Doctrine ODM? here is my code:

 public function indexAction()
    {           
        $dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
        $calendars = $dm->createQueryBuilder('Calendar\Document\Calendar')->getQuery()->execute();
    }

when I run

<?php var_dump($this->calendars); ?> 

in .phtml it retruns null, how I get the query result in .phtml?

도움이 되었습니까?

해결책

I think you should return the variable $calendars in a ViewModel in your indexAction. Try this :

public function indexAction()
{           
    $dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
    $calendars = $dm->createQueryBuilder('Calendar\Document\Calendar')->getQuery()->execute();


    $viewModel = new ViewModel(array('calendars'=>$calendars));
    return $viewModel;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top