2013-09-29 29 views
0

我正在使用symfony 2.2.3FOSRestBundle實施Restful Web服務。創建參數化安靜Web服務時未找到路由錯誤

這裏是我的代碼,但是當我火了以下網址我收到以下錯誤

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" 
+0

您是否在app/config/routing.yml中註冊了包路由?另外在終端中輸入php app/console router:debug。它會列出所有可用的路線。 – Onema

+0

我編輯了這個問題,但我不知道如何用'app/console router:debug'來做到這一點 – Hunt

回答

1

只是爲了確保,是這來自HubHomeBundle/Resources/config/routing.yml?

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

如果是這樣嘗試編輯它,將其更改爲:

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

你的「資源」標籤的值應該是控制器類的完全合格的名稱,而不是文件路徑

+0

不,我得到了同樣的錯誤 – Hunt

+0

轉到你的項目的根目錄(你可以看到應用程序,配置,日誌,資源目錄)並運行'php應用程序/控制檯路由器:調試'你的輸出是什麼? – flivan

相關問題