Slim 外部路由文件错误
Slim external route file error
我开始使用 Slim (3.8.1)。我正在玩门票样本。
因为我正在考虑一个更大的应用程序,所以我希望将我的路由放在单独的文件中。但是当我在我的 index.php 中包含路由文件时,我收到了这个错误:
"Catchable fatal error: Argument 1 passed to Closure::{closure}() must be an instance of Request, instance of Slim\Http\Request given"
这是我的路由文件(之前 index.php 中内容的简单副本,包含在 php 标签中):
<?php
$app->get('/tickets', function (Request $request, Response $response) {
$this->logger->addInfo("Ticket list");
$mapper = new TicketMapper($this->db);
$tickets = $mapper->getTickets();
$response = $this->view->render($response, "tickets.phtml", ["tickets" => $tickets, "router" => $this->router]);
return $response;
});
?>
在我的 index.php 文件中,我现在有这个:
require '../routes/tickets.php';
我是否必须以某种方式注册路由文件的路径?
感谢任何帮助。
此致,
乔治
我认为在外部路由文件中可以执行以下操作:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app->get('/', function (Request $request, Response $response)
{
$response = $this->view->render($response, "home.phtml");
return $response;
});
?>
我开始使用 Slim (3.8.1)。我正在玩门票样本。
因为我正在考虑一个更大的应用程序,所以我希望将我的路由放在单独的文件中。但是当我在我的 index.php 中包含路由文件时,我收到了这个错误:
"Catchable fatal error: Argument 1 passed to Closure::{closure}() must be an instance of Request, instance of Slim\Http\Request given"
这是我的路由文件(之前 index.php 中内容的简单副本,包含在 php 标签中):
<?php
$app->get('/tickets', function (Request $request, Response $response) {
$this->logger->addInfo("Ticket list");
$mapper = new TicketMapper($this->db);
$tickets = $mapper->getTickets();
$response = $this->view->render($response, "tickets.phtml", ["tickets" => $tickets, "router" => $this->router]);
return $response;
});
?>
在我的 index.php 文件中,我现在有这个:
require '../routes/tickets.php';
我是否必须以某种方式注册路由文件的路径?
感谢任何帮助。
此致, 乔治
我认为在外部路由文件中可以执行以下操作:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app->get('/', function (Request $request, Response $response)
{
$response = $this->view->render($response, "home.phtml");
return $response;
});
?>