2017-03-17 69 views
0

做我的第一個應用程序從http://knpuniversity.com/screencast/symfony/ 這是非標準的錯誤,但我不知道如何調試它,事業debug:error路線/genus/{genusName}是存在Symfony2的:未找到路線「GET /屬/章魚/」

genus/{genusName}/notes工作良好)

的routing.yml

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

的src /的appbundle /控制器/ GenusController.php

<?php 
namespace AppBundle\Controller; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; 
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\JsonResponse; 
use Symfony\Component\HttpFoundation\Response; 
class GenusController extends Controller 
{ 
    /** 
    * @Route("/genus/{genusName}") 
    */ 
    public function showAction($genusName) 
    { 
     return $this->render('genus/show.html.twig', array(
      'name' => $genusName, 
     )); 
    } 
    /** 
    * @Route("/genus/{genusName}/notes", name="genus_show_notes") 
    * @Method("GET") 
    */ 
    public function getNotesAction($genusName) 
    { 
     $notes = [ 
      ['id' => 1, 'username' => 'AquaPelham', 'avatarUri' => '/images/leanna.jpeg', 'note' => 'Octopus asked me a riddle, outsmarted me', 'date' => 'Dec. 10, 2015'], 
      ['id' => 2, 'username' => 'AquaWeaver', 'avatarUri' => '/images/ryan.jpeg', 'note' => 'I counted 8 legs... as they wrapped around me', 'date' => 'Dec. 1, 2015'], 
      ['id' => 3, 'username' => 'AquaPelham', 'avatarUri' => '/images/leanna.jpeg', 'note' => 'Inked!', 'date' => 'Aug. 20, 2015'], 
     ]; 
     $data = [ 
      'notes' => $notes 
     ]; 
     return new JsonResponse($data); 
    } 
} 

應用程序/資源/視圖/屬/ show.html.twig

{% extends 'base.html.twig' %} 
{% block title %}Genus {{ name }}{% endblock %} 
{% block body %} 
    <h2 class="genus-name">{{ name }}</h2> 
    <a href="{{ path('genus_show_notes', {'genusName': name}) }}">Json Notes</a> 
    <div class="sea-creature-container"> 
     <div class="genus-photo"></div> 
     <div class="genus-details"> 
      <dl class="genus-details-list"> 
       <dt>Subfamily:</dt> 
       <dd>Octopodinae</dd> 
       <dt>Known Species:</dt> 
       <dd>289</dd> 
       <dt>Fun Fact:</dt> 
       <dd>Octopuses can change the color of their body in just three-tenths of a second!</dd> 
      </dl> 
     </div> 
    </div> 
    <div class="notes-container"> 
     <h2 class="notes-header">Notes</h2> 
     <div><i class="fa fa-plus plus-btn"></i></div> 
    </div> 
    <section id="cd-timeline"></section> 
{% endblock %} 

調試:路線http://joxi.ru/Dr8j6YniOx3E26(對不起,我可以粘貼聲譽的唯一網址原因)

回答

1

路線中的路徑配置不包含尾部斜線。爲了使您的示例能夠正常工作,您需要在嘗試訪問控制器時(例如,/genus/octopus而不是/genus/octopus/)刪除尾部斜線,或者將斜槓添加到路由配置中。

+0

哦,這麼容易!謝謝! – SidSpears