Question

i make a setting action in which i used doctrine query for getting single result but it returns null while data exist in database,how i get single result?here is my code:

public function settingsAction()
    {
            $id = (int) $this->params()->fromRoute('id', 0);
            if (!$id) {
                return $this->redirect()->toRoute('calendar', array(
                    'action' => 'create'
                ));
            }   
                 //echo $id;
            //$calendar = $id;//$this->getCalendarTable()->getCalendar($id);
            $calendar = $documentManager->getRepository('Calendar\Document\Calendar')->find($id);
            $form  = new CalendarForm();
            $form->bind($calendar);
            $form->get('submit')->setAttribute('value', 'Save');

            $request = $this->getRequest();
            if ($request->isPost()) {
                $form->setInputFilter($calendar->getInputFilter());
                $form->setData($request->getPost());

                if ($form->isValid()) {
                    //$this->getCalendarTable()->saveCalendar($form->getData());
                    return $this->redirect()->toRoute('calendar', array('action' => 'show', 'id' => $id));
                }
            }

            return array(
                'id' => $id,
                'form' => $form,
            );
    }
Was it helpful?

Solution

You don't need to create a query to fetch by id as the DocumentRepository already provides this via it's find($id) method.

Just use the document manager to fetch the repository

$document = $documentManager->getRepository('FooDocument')->find($id);

You can also use the convenience method find($documentName, $id) directly on the document manager.

$document = $documentManager->find('FooDocument', $id);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top