laracast (https://laracasts.com/series/php-for-beginners)에서이 자습서를 수행 중이며이 시리즈 (16 - 라우터 만들기)에 있습니다. 기본적인 라우터를 만드는 법을 보여줍니다. 동영상에서 설명한대로 내 지식을 다 해봤지만 라우터를 만드는 데 문제가 있습니다. 나는이 오류를 통과합니까 어떻게이 uri에 대한 경로가 정의되어 있지 않습니다.
Fatal error: Uncaught exception 'Exception' with message 'No routes define for this uri' in C:\wamp64\www\todo\core\Router.php on line 23 Exception: No routes define for this uri in C:\wamp64\www\todo\core\Router.php on line 23
: 이 오류 메시지를 받고 있어요? 당신이 나에게 알려 더 많은 정보를 필요로하는 경우
$router->define([
'' => 'controllers/index.php',
'about' => 'controllers/about.php',
'contact' => 'controllers/contact.php'
]);
Router.php
class Router
{
protected $routes = [];
// this function defines our routes
public function define($routes)
{
# code...
$this->routes = $routes;
}
public function direct($uri){
if (array_key_exists($uri, $this->routes)) {
# code...
return $this->routes[$uri];
}
throw new Exception("No routes define for this uri");
}
}
Index.php는
$database = require 'core/bootstrap.php';
$router = new Router;
require 'routes.php';
$uri = trim($_SERVER['REQUEST_URI'], '/');
require $router->direct($uri);
: 여기 내 코드는
routes.php 있습니다.
UPDATE 이 wampserver www가 폴더에 내 사이트 구조입니다 :
자세한 내용을 알려면 오류 메시지를 변경하십시오. 어쩌면''이 경로를 정의하는 경로가 없습니다 : $ uri "''당신이 누락 된 경로를 알려줍니다. – miken32
'예외'메시지와 함께 '예외가이 uri : todo에 정의되어 있습니다' –
그게 내가 얻은 것입니다. –