我在php上关注Laravel Cast tuotrial,却陷入了困境 尝试路由某些文件时,出现错误
“致命错误:未捕获的异常:在C:\ xampp \ htdocs \ Php-Learning \ core \ Router.php:27堆栈跟踪中,未为此URI定义任何路由:
#0 C:\ xampp \ htdocs \ Php-Learning \ index.php(6):Router-> direct('Php-Learning / in ...')
在第27行的C:\ xampp \ htdocs \ Php-Learning \ core \ Router.php中抛出#1 {main}。
我对此坚持了几天,我试图找到一些解决方案,但没有一项工作> 我使用所有找到的.htaccess解决方案,但从未解决问题。 这是解决问题的常用方法,但我从来没有为我工作
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /index.php [L,QSA]
请问有人可以帮忙吗 感谢您的帮助。
我不太了解我必须发布什么文件,因此我将这两个文件放在这里 这是我的生成方式
<?php
$router->define([
'' => 'controllers/index.php',
'about' => 'controllers/about.php',
'about/culture' => 'controllers/about-culture.php',
'contact' => 'controllers/contact.php'
]);
这是路由器文件
<?php
class Router
{
protected $routes = [];
public static function load($file)
{
$router = new static;
require $file;
return $router;
}
public function define($routes)
{
$this->routes = $routes;
}
public function direct($uri)
{
if (array_key_exists($uri, $this->routes)) {
return $this->routes[$uri];
}
throw new Exception('No route defined for this URI.');
}
}
谢谢