PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

[FIXED] No route found, symfony

 February 10, 2022     symfony     No comments   

Issue

I am following Symfonycast's symfony tutorial and I'm up to the voting system part. All my ajax requests are 404 because the url is not right but I have no clue how to fix it myself. I have used the code provided by the site.

Here is my controller :

<?php
namespace App\Controller;

use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
class CommentController extends AbstractController
{
    /**
     * @Route("/comments/{id}/vote/{direction<up>|<down>}", name="app_comment_show", methods="POST")
    */
    public function commentVote($id, $direction, LoggerInterface $logger)
    {

        if ($direction === 'up') {
            $logger->info('Voting up');
            $currentVoteCount = rand(7, 100);
        } else {
            $logger->info('Voting down');
            $currentVoteCount = rand(0, 5);
        }
        return $this->json(['votes' => $currentVoteCount]);
    }
}

Here is the javascript used :

 var $container = $('.js-vote-arrows');
 $container.find('a').on('click', function(e) {
     e.preventDefault();
     var $link = $(e.currentTarget);
 
     $.ajax({
         url: '/comments/10/vote/'+$link.data('direction'),
         method: 'POST'
     }).then(function(data) {
         $container.find('.js-vote-total').text(data.votes);
     });
 });

If I let it as it's written POST http://127.0.0.1/comments/10/vote/up 404 (Not Found) I suppose the correct URL would be 127.0.0.1/dev/public/question/reversing-a-spell/comments/10/vote/up ?

I have no clue and I'm stuck


Solution

I decided to dump xampp and use symfony serve -d to launch the server and the provided code worked then.



Answered By - Maxime Michon
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing