Slim + Twig 上的 urlFor() 错误
Error with urlFor() on Slim + Twig
我在 Slim 说
时收到错误消息
Message: An exception has been thrown during the rendering of a template
("Named route not found for name: userList") in "sidebar.twig" at line 7.
我的看法是
{% extends 'base.twig' %}
{% block title %} Índice {% endblock title %}
{% block content %}
<div class="row">
<div class="container">
{% include "sidebar.twig" %}
我的看法sidebar.twig如下:
<div class="col-lg-4 col-md-4 col-xs-4">
<div class="dropdown menu col-lg-9 col-md-9 col-xs-9">
<ul class="nav nav-pills nav-stacked">
<li><a tabindex="-1" href="#">GESTIÓN DE PARTICIPANTES</a></li>
{% if authorized %}
<li><a tabindex="-1" href="{{ urlFor('userList') }}">GESTION DE USUARIOS</a></li>
{% endif %}
</ul>
</div>
</div>
视图 + 模型代码
$app->get('/users', function() use ($app, $authorized,$users)
{
$app->render('users.twig',array('users' => $users, 'is_admin' => $authorized));
})->name('userList');
github 中的代码是 => https://github.com/Mangulomx/olimpiada
在我看来,您没有在项目的任何位置加载 users.php 路由文件。如果未加载,则错误是正确的,因为它不知道基于加载的路由的路由。您可能想将 ../routes/users.php 添加到 public/index.php.
我在 Slim 说
时收到错误消息Message: An exception has been thrown during the rendering of a template
("Named route not found for name: userList") in "sidebar.twig" at line 7.
我的看法是
{% extends 'base.twig' %}
{% block title %} Índice {% endblock title %}
{% block content %}
<div class="row">
<div class="container">
{% include "sidebar.twig" %}
我的看法sidebar.twig如下:
<div class="col-lg-4 col-md-4 col-xs-4">
<div class="dropdown menu col-lg-9 col-md-9 col-xs-9">
<ul class="nav nav-pills nav-stacked">
<li><a tabindex="-1" href="#">GESTIÓN DE PARTICIPANTES</a></li>
{% if authorized %}
<li><a tabindex="-1" href="{{ urlFor('userList') }}">GESTION DE USUARIOS</a></li>
{% endif %}
</ul>
</div>
</div>
视图 + 模型代码
$app->get('/users', function() use ($app, $authorized,$users)
{
$app->render('users.twig',array('users' => $users, 'is_admin' => $authorized));
})->name('userList');
github 中的代码是 => https://github.com/Mangulomx/olimpiada
在我看来,您没有在项目的任何位置加载 users.php 路由文件。如果未加载,则错误是正确的,因为它不知道基于加载的路由的路由。您可能想将 ../routes/users.php 添加到 public/index.php.