Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 routing with annotations

I am trying to define my routes using annotations in symfony2. My Bundle name is PatentBundle. But I am getting an error of

No route found for "GET /portfolio/

My app/config/routing.yml

MunichInnovationGroupPatentBundle:
resource: "@MunichInnovationGroupPatentBundle/Controller/"
type:     annotation
prefix:   /
defaults:  { _controller: "MunichInnovationGroupPatentBundle:Default:index" }

My portfolio controller looks like

<?php
 namespace MunichInnovationGroup\PatentBundle\Controller;

 use MunichInnovationGroup\PatentBundle\Entity\Log;

 use MunichInnovationGroup\PatentBundle\Entity\UserPatent;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpFoundation\Request;
 use JMS\SecurityExtraBundle\Annotation\Secure;
 use Symfony\Component\Security\Core\Exception\AccessDeniedException;
 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 MunichInnovationGroup\PatentBundle\Entity\SvPatents;
 use MunichInnovationGroup\PatentBundle\Entity\PmPortfolios;
 use MunichInnovationGroup\PatentBundle\Entity\UmUsers;
 use MunichInnovationGroup\PatentBundle\Form\PatentType;
 use MunichInnovationGroup\PatentBundle\Entity\PmPatentgroups;
 use Symfony\Component\Security\Core\SecurityContext;
 use MunichInnovationGroup\PatentBundle\Util\SecurityHelper;
 use Exception;

/**
 * Portfolio controller.
 * @Route("/portfolio")
*/
class PortfolioController extends Controller {

/**
 * Index action.
 *
 * @Route("/", name="portfolio")
 * @Method({"GET", "POST"})
 * @Template("MunichInnovationGroupBundle:Portfolio:show.html.twig")
 */
public function indexAction(Request $request) {
      // method code goes here
    }
like image 360
Zoha Ali Khan Avatar asked Jun 16 '12 15:06

Zoha Ali Khan


2 Answers

# app/config/routing.yml

MunichInnovationGroupPatentBundle:

    resource: "@MunichInnovationGroupPatentBundle/Controller/DefaultController.php"
    type:     annotation
    prefix:   /

The controller should have:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
like image 184
Dave Mascia Avatar answered Nov 18 '22 00:11

Dave Mascia


If you are in the developement environment check you import the routing.yml in routing_dev.yml:

# app/config/routing_dev.yml

_main:
    resource: routing.yml
like image 35
Visavì Avatar answered Nov 18 '22 00:11

Visavì