Я пытаюсь сделать шаблон ветки внутри другого шаблона ветки, но он не работает. я получил эту ошибку:
Любая помощь будет оценена!
Во время рендеринга шаблона было сгенерировано исключение
несоответствие между загруженными и объявленными именами классов:
FLY \ BookingsBundle \ Controller \ postController vs
FLY \ BookingsBundle \ Controller \ PostController «) в
SonataUserBundle: Профиль: show.html.twig в строке 94.
show.html.twig
{% extends "SonataUserBundle:Profile:action.html.twig" %}
{% block body %}
{% block content %}
{{ render(controller('FLYBookingsBundle:post:new')) }}
{% endblock content %}
{% endblock %}
это мой контроллер:
<?php
namespace FLY\BookingsBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use FLY\BookingsBundle\Entity\Post;
use FLY\BookingsBundle\Form\PostType;
/**
* Post controller.
*
* @Route("/post")
*/
class PostController extends Controller
{
/**
* Lists all Post entities.
*
* @Route("/", name="post")
* @Method("GET")
* @Template()
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$findEntities = $em->getRepository('FLYBookingsBundle:Post')->findAll();
$entities = $this->get('knp_paginator')->paginate($findEntities,$this->get('request')->query->get('page', 1),9
);
return array(
'entities' => $entities,
);
}
/**
* Creates a new Post entity.
*
* @Route("/", name="post_create")
* @Method("POST")
* @Template("FLYBookingsBundle:Post:new.html.twig")
*/
public function createAction(Request $request)
{
$entity = new Post();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('post_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Creates a form to create a Post entity.
*
* @param Post $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Post $entity)
{
$form = $this->createForm(new PostType(), $entity, array(
'action' => $this->generateUrl('post_create'),
'method' => 'POST',
));return $form;
}
/**
* Displays a form to create a new Post entity.
*
* @Route("/new", name="post_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
$entity = new Post();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Finds and displays a Post entity.
*
* @Route("/{id}", name="post_show")
* @Method("GET")
* @Template()
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FLYBookingsBundle:Post')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Post entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
/**
* Displays a form to edit an existing Post entity.
*
* @Route("/{id}/edit", name="post_edit")
* @Method("GET")
* @Template()
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FLYBookingsBundle:Post')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Post entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Creates a form to edit a Post entity.
*
* @param Post $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Post $entity)
{
$form = $this->createForm(new PostType(), $entity, array(
'action' => $this->generateUrl('post_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
/**
* Edits an existing Post entity.
*
* @Route("/{id}", name="post_update")
* @Method("PUT")
* @Template("FLYBookingsBundle:Post:edit.html.twig")
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FLYBookingsBundle:Post')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Post entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('post_edit', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Deletes a Post entity.
*
* @Route("/{id}", name="post_delete")
* @Method("DELETE")
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FLYBookingsBundle:Post')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Post entity.');
}
$em->remove($entity);
$em->flush();
}
return $this->redirect($this->generateUrl('post'));
}
/**
* Creates a form to delete a Post entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('post_delete', array('id' => $id)))
->setMethod('DELETE')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
}
Вам нужно изменить регистр post
в шаблоне ветки измените:
{{ render(controller('FLYBookingsBundle:post:new')) }}
в
{{ render(controller('FLYBookingsBundle:Post:new')) }}
и ты должен быть хорошим
Других решений пока нет …