I've added a route in my controller but it does not work even though i can see it in router:debug from the console.
/**
* @Route("/apilucky", name="lucky")
*/
public function numberAction(Request $request)
{
// returns '{"username":"jane.doe"}' and sets the proper Content-Type header
return $this->json(array('username' => 'jane.doe'));
}
I get a 404 message when i visit it from my browser or postman, but when I launch "php app/console router:debug " everything looks fine (carbon copy output from a existing/working route):
working route (i had to do screenshots, formatting was not readable after copy/paste here)
I'm new to symfony but this looks like an easy fix. Did I forget to clear/refresh anything ? (I tried running "php app/console clear:cache" but it did not help).
edit: Cache was cleared on client as well.
The address i'm trying to access is www.serverurl.fr/fr/apilucky
The controller file is huge (there is a ton of other routes (i did not set them up) that are working, but here's an extract:
<?php
namespace App\CoreBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* @Route("/")
*/
class WebviewController extends BaseController
{
// ...
/**
* @Route("/accounts", name="accounts")
*/
public function AccountsAction(Request $request)
{
$accounts = $this->getDoctrine()->getManager()->getRepository('AppCoreBundle:Account')->findAll();
$accountsArray = array();
foreach ($accounts as $account) {
$HasWeboob = $account->getWeboob();
if ($HasWeboob) {
$accountsArray[] = array(
'id_weboob' => $account->getWeboob(),
'account_name' => $account->getName(),
'account_id' => $account->getId(),
);
}
}
return new JsonResponse($accountsArray);
}
/**
* @Route("/apilucky", name="lucky")
*/
public function numberAction(Request $request)
{
// returns '{"username":"jane.doe"}' and sets the proper Content-Type header
return $this->json(array('username' => 'jane.doe'));
}
}
Thanks a lot.
Cheers, Julien
SOLUTION:
I cleared the cache on the server side and it worked. php app/console clear:cache --env=prod