php - 尽管在我调试时路由存在,但无法为路由生成 URL
问题描述
我提出了这个异常:
RouteNotFoundException
RuntimeError
HTTP 500 Internal Server Error
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "listecours" as such route does not exist.").
在我的树枝模板(包含 的行path('listecours')
)的此时提出:
</li>
<li class="nav-item active">
<a href="{{ path('listexercices') }}" class="nav-link">Liste d'exercices</a>
</li>
<li class="nav-item active">
<a href="{{ path('listecours') }}" class="nav-link">Liste des cours</a>
</li>
{% else %}
<li class="nav-item active">
<a href="{{ path('listexercices') }}" class="nav-link">Liste d'exercices</a>
</li>
虽然路线是正确的(我想)在我的 CoursController 中使用注释声明:
<?php
namespace App\Controller;
use App\Repository\CoursRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class CoursController extends AbstractController
{
/**
* @Route("/cours", name="cours")
*/
public function index()
{
return $this->render('cours/index.html.twig', [
'controller_name' => 'CoursController',
]);
}
/**
* @Route("/listecours", name="listecours")
*/
public function listeCours(CoursRepository $cours){
return $this->render('cours/cours.html.twig', [
'cours' => $cours->findAll()
]);
}
}
该行php bin/console debug:router
产生了这个输出,表明该路线确实存在:
-------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format}
_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_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_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
cours ANY ANY ANY /cours
listecours ANY ANY ANY /listecours
exercices ANY ANY ANY /exercices
listexercices ANY ANY ANY /listexercices
main ANY ANY ANY /main
prof ANY ANY ANY /prof
listetudiants ANY ANY ANY /listetudiants
registration ANY ANY ANY /registration
app_login ANY ANY ANY /
app_logout ANY ANY ANY /logout
-------------------------- -------- -------- ------ -----------------------------------
我仍然不明白为什么异常会无缘无故地被提出来,以至于这很烦人。我对 Twig 代码中的其他路由做了完全相同的事情,并且在我添加最后一个之前它工作得非常好。
这里的目标是能够停止出现此异常并让路由正常工作。
请帮助实现这一目标?如果您需要更多信息,请告诉我。
谢谢。
解决方案
没有什么能真正解决这个非常烦人的“问题”,我尝试多次清除缓存,它没有做任何事情。然后我看到有人说在安装apache-pack
with composer 之后就成功了。我试过了,它奏效了......去看看。
推荐阅读
- swift - 为什么我的 UIViewController 在断点执行 `po` 时无法释放
- react-native - 世博会 - 预定通知。将应用程序置于前台
- react-native - useNativeDriver 在 Android 上的特定动画中不起作用
- android - YouTubeStandalonePlayer.createVideoIntent (*context*, YTapiKey, videoID) 的上下文参数是什么?
- python - API Power BI 获取令牌但获取请求获取响应 401
- python - 将同一列数据拆分为多列
- excel - 我的图表不反映 VBA 代码创建的数据
- typescript - 为什么我不能使用 StyleProp
在我自己的组件上 - ios - iOS 13 打破 UIViewPropertyAnimator 过渡
- javascript - 嵌套树的递归函数不按“顺序”返回