我得到了例外:
在渲染模板期间抛出了异常(&#34;无法生成指定路径的URL&#34; allPrograms&#34;因为这样的路线不存在。&#34;)。< / p>
事情是......路线确实存在:
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.
}
...
}
这里是调用它的树枝模板的相关部分:
<a href="{{ path('allPrograms') }}">
我的代码顶部有use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
。我还在routing.yml
:
admin:
resource: "@AdminBundle/Controller/"
type: annotation
prefix: /
这是app/console debug:router
显示的内容:
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
正如您所看到的,我定义了其他命名路由,它们可以正常工作。我的路由器调试还会显示问题/admin/program method:Any
中的路由,但不显示名称。
我试过了: 清除/加热缓存: php app / console cache:clear --env = prod php app / console cache:clear --env = dev php app / console cache:清除 php app / console cache:warmup --env = prod --no-debug
Removing composer vendor and:
composer -vvv update
Recreating composer autoload:
composer -vvv dump-autoload -o
有没有人知道为什么我的命名路线在Symfony中找不到?
更新
我应该提到,我已经尝试在我的树枝模板中使用admin__program_index
......是的,它确实有效。但是,我想使用我的命名路线,我不知道它为什么不起作用。
我在其他控制器中使用命名路由:
namespace Admin\Bundle\Controller;
use ...
class ConfigController extends AdminController {
/**
* @Route("/admin/config", name="config")
* @return Response
*/
public function indexAction() {
//do stuff
}
}
此命名路线完美无缺。
答案 0 :(得分:1)
此处您的路线逻辑上是例如:
admin__program_index
用于请求ANY
/admin/program
admin__program_edit
用于请求PUT
/admin/program
admin__program_create
用于请求POST
/admin/program
admin__program_delete
用于请求DELETE
/admin/program
如果您无法理解,可以运行命令:
app/console debug:router --show-controllers
这是带有routes
Controllers
尝试更改 <a href="{{ path('allPrograms') }}">
<a href="{{ path('admin__program_index') }}">