2017-08-18 68 views
1

我的routing.yml:找不到路線,Symfony的路由更新不及時正確

user_user: 
    resource: "@UserUserBundle/Resources/config/routing.yml" 
    prefix: /user 

book_book: 
    resource: "@BookBookBundle/Resources/config/routing.yml" 
    prefix: /book 

index_index: 
    resource: "@IndexIndexBundle/Resources/config/routing.yml" 
    prefix: /


app: 
    resource: "@AppBundle/Controller/" 
    type:  annotation 

fos_user: 
    resource: "@FOSUserBundle/Resources/config/routing/all.xml" 

app_api: 
    resource: "@AppBundle/Controller/Api" 
    type:  annotation 

mvms_api: 
    type:  rest 
    prefix: /api 
    resource: "@AppBundle/Resources/config/api-routing.yml" 

API-的routing.yml:

blog_api_articles: 
    type: rest 
    resource: "@AppBundle/Controller/ArticlesController.php" 
    name_prefix: api_article_ 


blog_api_reviews: 
    type: rest 
    resource: "@AppBundle/Controller/ReviewsController.php" 
    name_prefix: api_reviews_ 


api_reviewsPut: 
    type: rest 
    resource: "@AppBundle/Controller/PutController.php" 
    name_prefix: api_put_ 

我的PHP斌/控制檯調試:路由器

... 
    api_article_get_article    GET  ANY  ANY /api/articles/{id}.{_format} 
    api_reviews_get_review    GET  ANY  ANY /api/reviews/{id}.{_format} 

當我在API-routing.yml中的應用進入新的路線只是不刻意去參加我的API路由中的最後一項似乎並沒有被工作/顯示...

//This works fine 
    class ReviewsController extends Controller 
{ 

    /** 
    * Note: here the name is important 
    * get => the action is restricted to GET HTTP method 
    * Article => (without s) generate /articles/SOMETHING 
    * Action => standard things for symfony for a controller method which 
    *   generate an output 
    * 
    * it generates so the route GET .../articles/{id} 
    */ 
    public function getReviewAction($id) 
    { 

      $someId = $id; 
      $rv = $this->getDoctrine()->getManager(); 
      $review = $rv->createQuery(
       'SELECT * FROM AppBundle:Something r WHERE r.id= :id')->setParameter('id', $someId); 

      $reviews = $review->getResult(); 
     if (empty($reviews)) { 
      return array('Data' => 'none'); 
     } 
     else 
      return $reviews; 
    } 




} 


class PutController 
{ 
    public function putReviewsPut($id) 
    { 

     $someId = $id; 
     $rv = $this->getDoctrine()->getManager(); 
     $review = $rv->createQuery(
      'some query')->setParameter('id', $someId); 

     $reviews = $review->getResult(); 
     if (empty($reviews)) { 
      return array('Data' => 'none'); 
     } 
     else 
      return $reviews; 
    } 
} 

他們考慮在內。 因此我得到GET/API「未找到\路徑」 /把/ 1 \「」, 在郵差

我試圖重新啓動服務器 而且還試圖 PHP斌/控制檯高速緩存:明確 - env prod

在Windows 10上運行Xampp並使用phpStorm進行編輯。

昨晚我和api_reviews_的問題完全一樣,但不知何故,它決定最終工作。

+0

你嘗試清除緩存? –

+0

@ImanaliMamadiev Yep –

+0

它與複數有關......最終需要有一個S。我會詳細說明,如果我理解它 –

回答

4

您應該在控制器方法中使用後綴Action

那麼試試這個:

class PutController 
{ 
    public function putReviewsPutAction($id) 
    { 

取而代之的是:

class PutController 
{ 
    public function putReviewsPut($id) 
    { 

希望這有助於

+1

關於正確的聲音。工作。 –