0

我正在使用symfony 2.2.3withFOSRestBundle来实现Restfulweb 服务。

这是我的代码,但是当我触发以下网址时,我收到以下错误

No route found for "GET /business/john"

这是控制器代码

use FOS\RestBundle\Controller\Annotations as Rest;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Symfony\Component\Security\Core\Exception\AccessDeniedException;

use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;

class BusinessController extends Controller {


        public function getBusinessAction($para){


          return new JsonResponse(array('name' => $para));
        } 

}

这是我的网址

http://localhost/symfony/web/app_dev.php/business/john

这是我的路线

如果我从 url 和函数中删除参数,getBusinessAction那么它可以工作但不能使用参数/

_business:
    resource: "@HubHomeBundle/Controller/BusinessController.php"    
    type: rest

更新

里面app/confing/routing.yml

   hub_home:
    resource: "@HubHomeBundle/Resources/config/routing.yml"
4

1 回答 1

1

只是为了确定,这是来自 HubHomeBundle/Resources/config/routing.yml 吗?

_business:
    resource: "@HubHomeBundle/Controller/BusinessController.php"    
    type: rest

如果是这样,请尝试对其进行编辑并将其更改为:

_business:
    resource: HubHomeBundle\Controller\BusinessController   
    type: rest

您的“资源”标签的值应该是控制器类的完全限定名称,而不是文件的路径

于 2013-10-02T13:10:00.950 回答