I've got a problem with routing in my project.
I have 2 controllers, one is
Domestos\TranslatingBundle\ProjectController.php
p
and second is
Domestos\TranslatingBundle\LanguageController.php
Also i have routing set up with annotations.
routing.yml:
# import routes from a controller directory
translation:
resource: "@DomestosTranslatingBundle/Controller/"
type: annotation
ProjectController works great, router is working, great.
Problem is, that my LanguageController is not working. Controller should be done ok, but always when i call URL with route predefined in annotation, it throw error
No route found for "GET /language/" 404 Not Found - NotFoundHttpException 1 linked Exception:
ResourceNotFoundException »
LanguageController.php looks like this:
<?php
namespace Domestos\TranslatingBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Domestos\TranslatingBundle\Entity\Language;
class LanguageController extends Controller
{
/**
* @Route("/language")
* @Template()
*/
public function indexAction()
{
$languages = $this->getDoctrine()->getRepository('DomestosTranslatingBundle:Language')->findAll();
return $this->render('DomestosTranslatingBundle:Language:index.html.twig', array(
'languages' => $languages,
));
}
/**
* @Route("/language//add")
* @Template()
*/
public function addAction()
{
$language = new Language();
$language->setTitle('Jazyk')
->setCode('Skratka');
$form = $this->createFormBuilder($language)
->add('title', 'text')
->add('code', 'text')
->add('save', 'submit')
->getForm();
$form->handleRequest($request);
if($form->isSubmitted())
{
$em = $this->getDoctrine()->getManager();
$em->persist($language);
$em->flush();
}
return $this->render('DomestosTranslatingBundle:Language:add.html.twig', array(
'form' => $form->createView(),
));
}
/**
* @Route("/language/edit/{id}")
* @Template()
*/
public function editAction($id)
{
$language = $this->getDoctrine->getRepository('DomestosTranslatingBundle:Language')->find($id);
$form = $this->createFormBuilder($language)
->add('title', 'text')
->add('code', 'text')
->add('save', 'submit')
->getForm();
$form->handleRequest($request);
if($form->isSubmitted())
{
$em = $this->getDoctrine()->getManager();
$em->persist($language);
$em->flush();
}
return $this->render('DomestosTranslatingBundle:Language:edit.html.twig', array(
'form' => $form->createView(),
));
}
/**
* @Route("/language/delete/{id}")
* @Template()
*/
public function deleteAction($id)
{
$language = $this->getDoctrine->getRepository('DomestosTranslatingBundle:Language')->find($id);
$em = $this->getDoctrine()->getManager();
$em->remove($language);
$em->flush();
return new Response('Language deleted: ' . $language->getCode());
}
}
The question is, why is this controller not working? I need to finish project, and this is really annoying.
@Route("/language//add")
? – Bartek