I am sorry for asking such a question and I know there have been questions like this before, but my case is rather...stupid. What I have is a project management system and I want to display all projects which works fine and is auto generated by Symfony. In the same controller which is ProjectController I made another action. I wanted to list all archived projects which have been completely done. For a start I simply copy pasted the code and the annotations and changed the routes and the name of the function. Here is my indexAction function
/**
* Lists all project entities.
*
* @Route("/", name="project_index")
* @Method("GET")
*/
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$projects = $em->getRepository('AppBundle:Project')->findAll();
return $this->render('project/index.html.twig', array(
'projects' => $projects,
));
}
It is as simple as it can get. Now here is my archiveAction function which is the same
/**
* Lists all project entities.
*
* @Route("/archive", name="project_archive")
* @Method("GET")
*/
public function archiveAction()
{
$em = $this->getDoctrine()->getManager();
$projects = $em->getRepository('AppBundle:Project')->findAll();
return $this->render('project/index.html.twig', array(
'projects' => $projects,
));
}
So far I am not even filtering the projects, but doing the exact same thing as I do in the indexAction function and bear in mind both functions are in the same controller. Here is the error I receive when trying to show all archived projects -
AppBundle\Entity\Project object not found.
The index action works just fine and displays all projects, but if I change the route and change the name of the function and keep everything the same and they are in the same Controller - in one case it can find AppBUndle\Entity\Zadanie, but in the other case - it can't.
SOLVED I managed to solve the problem by putting the archive function on top. By on top I mean in first position before any other function. Before doing so I tried switching the routes. I took the route from indexAction and put it in the annotations from the archiveAction and the opposite. Both functions worked just fine. Then I returned them as they were and archive still didn't work. Then I simply put archive in first place before index and it worked as a charm. I have no idea what just happened and why but...didn't matter...it works. ( seriously though - if anybody knows why that is I would appreciate it)
EDIT: So 2 years and 4 months later I think I got the crank of it, the routes are cached so what I did was just clear the cache and it worked, but at the time I didnt pay attention to this detail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With