【发布时间】:2017-04-02 03:27:37
【问题描述】:
我开始使用 Slim (3.8.1)。我正在玩门票样本。
由于我正在考虑一个更大的应用程序,我希望将我的路线放在单独的文件中。但是当我在我的 index.php 中包含路由文件时,我收到了这个错误:
“可捕获的致命错误:传递给 Closure::{closure}() 的参数 1 必须是 Request 的实例,给定的 Slim\Http\Request 的实例”
这是我的路由文件(之前在 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';
我必须以某种方式注册路由文件的路径吗?
感谢任何帮助。
最好的问候, 乔治
【问题讨论】: