public function createAction()
{
// bind form to page model
$page = new Page();
$this->form->bind($this->request, $page);
if ($this->form->isValid()) {
try {
// path for page
$parent = $this->form->get('parent')->getData();
$path = $parent . '/' . $page->name;
// save page
$this->dm->persist($page, $path);
$this->dm->flush();
// redirect with message
$this->request->getSession()->setFlash('notice', 'Page created!');
return $this->redirect($this->generateUrl('admin'));
} catch (HTTPErrorException $e) {
$path = new PropertyPath('name');
$this->form->addError(new DataError('Name already in use.'), $path->getIterator());
}
}
return $this->render('SandboxAdminBundle:Admin:create.html.twig', array('form' => $this->form));
}