我得到了例外:
在呈现模板期间抛出异常(“无法生成指定路由的URL”allPrograms“因为此类路由不存在。”)。
事情是......路线确实存在:
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: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
有没有人有任何想法为什么我的命名路线没有在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
}
}
这条命名的路线完美无缺。
这里您的路线逻辑上是例如:
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') }}">