Reputation: 805
I'm getting the exception:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "allPrograms" as such route does not exist.").
Thing is... the route does exist:
namespace Admin\Bundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ProgramController extends AdminController {
private $config;
private $sqlConnection;
private $programMysqlDAO;
...
/**
* @Route("/admin/program", name="allPrograms")
*
* This will only trigger if there's no index.php
* @return Response
*/
public function indexAction() {
//do stuff.
}
...
}
Here's the relevant portion of the twig template that calls it:
<a href="{{ path('allPrograms') }}">
I have use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
at the top of my code. I also have the routing for this particular bundle configured in routing.yml
:
admin:
resource: "@AdminBundle/Controller/"
type: annotation
prefix: /
here's what app/console debug:router
shows:
Name Method Scheme Host Path
---------------------------------------------------- -------- -------- ------ ----------------------------------------------
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_info ANY ANY ANY /_profiler/info/{about}
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
admin__default_index ANY ANY ANY /
config ANY ANY ANY /admin/config
configIndex ANY ANY ANY /admin/config/{program}
admin__program_create POST ANY ANY /admin/program
admin__program_edit PUT ANY ANY /admin/program
admin__program_delete DELETE ANY ANY /admin/program
admin__program_index ANY ANY ANY /admin/program
queue_index GET ANY ANY /admin/queue
As you can see, I have other named routes defined, which work properly. My router debug also shows the route in question /admin/program method:Any
, but does not show the name.
I've tried: Clearing / warming the cache: php app/console cache:clear --env=prod php app/console cache:clear --env=dev php app/console cache:clear php app/console cache:warmup --env=prod --no-debug
Removing composer vendor and:
composer -vvv update
Recreating composer autoload:
composer -vvv dump-autoload -o
Does anyone have any ideas why my named route is not being found in Symfony?
UPDATE
I should have mentioned, I already tried using admin__program_index
in my twig template... and, yes, it does work. However, I want to use my named route and I have no idea why it's not working.
I'm using named routes in other controllers:
namespace Admin\Bundle\Controller;
use ...
class ConfigController extends AdminController {
/**
* @Route("/admin/config", name="config")
* @return Response
*/
public function indexAction() {
//do stuff
}
}
This named route works perfectly.
Upvotes: 2
Views: 9562
Reputation: 2654
Here your route is logically for example:
admin__program_index
is for request ANY
/admin/program
admin__program_edit
is for request PUT
/admin/program
admin__program_create
is for request POST
/admin/program
admin__program_delete
is for request DELETE
/admin/program
If you can't understand you can run command:
app/console debug:router --show-controllers
This is command show routes
with Controllers
Try change <a href="{{ path('allPrograms') }}">
to <a href="{{ path('admin__program_index') }}">
Upvotes: 2