I had a problem with this session too. Wenn I wrote the code(exactly like in video), the web keeping telling me "No route found for GET /../". I resolved it by a little change in show.html.twig: Orginal: < a href="{{ path('genus_show_notes', {'genusName':name} ) }}">Json Notes
Change to: < a href="{{ path('genus_show_notes', {'genusName':'name'} ) }}">Json Notes
Hello, I have problem. When i press link to Json, it shows
No route found for "GET /genussgs/notes" (from "http://localhost:8000/genus/sgs")
404 Not Found - NotFoundHttpException
1 linked Exception:
ResourceNotFoundException » . I am writing - "http://localhost:8000/genus/sgs" , and then I am having -"http://localhost:8000/genussgs/notes". If I not use link -"http://localhost:8000/genus/sgs/notes" it works perfectly.
Hmm... this seems very funny :/. Can you post your @Route code and also the code where you generate the link from your template? Something definitely isn't quite right.... but I'm not sure what yet.
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse;
class GenusController extends Controller { /** * @Route ("/genus/{genusName}") */
public function GenusController($genusName) { return $this->render('genus/show.html.twig', ['name'=>$genusName]);
{% block body %} <h2 class="genus-name">{{path('genus_show_notes', {'genusName':name}) }}</h2>
JSON notes <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></div> </div> <section id="cd-timeline">
I found it. Problem was in show.html.twig must be -" "/genus/{{ name }}/notes">JSON notes". My mistake was -" "/genus{{ name }}/notes">JSON notes". Anyway thank you for help.
Great catch! Actually, path() Twig function solves such kind of problems very well, you would love to use it further instead of compound URLs manually: {{ path('genus_show_notes', {'genusName': name}) }}
Cheers!
Please, log in to vote for this comment
|
Share Comment
"Houston: no signs of life" Start the conversation!
10 Comments
I had a problem with this session too. Wenn I wrote the code(exactly like in video), the web keeping telling me "No route found for GET /../". I resolved it by a little change in show.html.twig:
Orginal: < a href="{{ path('genus_show_notes', {'genusName':name} ) }}">Json Notes
Change to: < a href="{{ path('genus_show_notes', {'genusName':'name'} ) }}">Json Notes
(Add ' ' an name, holp it will help)
Hey Chuying He
That worked because you passed a string (name) to the route, instead of the variable, I believe your template is missing the "name" variable
Cheers!
[thumbs up]
Hello, I have problem. When i press link to Json, it shows
No route found for "GET /genussgs/notes" (from "http://localhost:8000/genus/sgs")
404 Not Found - NotFoundHttpException
1 linked Exception:
ResourceNotFoundException » . I am writing - "http://localhost:8000/genus/sgs" , and then I am having -"http://localhost:8000/genussgs/notes". If I not use link -"http://localhost:8000/genus/sgs/notes" it works perfectly.
Hey Oskaras Serelis!
Hmm... this seems very funny :/. Can you post your
@Routecode and also the code where you generate the link from your template? Something definitely isn't quite right.... but I'm not sure what yet.Cheers!
GenusController.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\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
class GenusController extends Controller
{
/**
* @Route ("/genus/{genusName}")
*/
public function GenusController($genusName)
{
return $this->render('genus/show.html.twig',
['name'=>$genusName]);
}
/**
* @Route("/genus/{genusName}/notes", name="genus_show_notes")
* @Method("GET")
*/
public function getNotesAction()
{
$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">{{path('genus_show_notes', {'genusName':name}) }}</h2>
JSON notes
<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></div>
</div>
<section id="cd-timeline">
</section>
{% endblock %}
Hey Oskaras Serelis
Look's like you are missing "genusName" parameter in your "getNoteAction" method, change it to this:
No route found for "GET /genusnotes/notes" (from "http://localhost:8000/genus/notes")and when I move my mouse to $genusName shows - "Unused parameter"
I found it. Problem was in show.html.twig must be -"
"/genus/{{ name }}/notes">JSON notes".
My mistake was -"
"/genus{{ name }}/notes">JSON notes". Anyway thank you for help.
Hey Oskaras,
Great catch! Actually, path() Twig function solves such kind of problems very well, you would love to use it further instead of compound URLs manually:
{{ path('genus_show_notes', {'genusName': name}) }}
Cheers!
"Houston: no signs of life"
Start the conversation!