Question

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?

Was it helpful?

Solution

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top