Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 没有为此uri定义路由_Php - Fatal编程技术网

Php 没有为此uri定义路由

Php 没有为此uri定义路由,php,Php,我正在学习laracast()的本教程,本系列中的这一集(16-制作路由器)。它展示了如何构建一个基本路由器。据我所知,我已经做了视频中所示的所有事情,但我在构建路由器时遇到了问题。 我收到以下错误消息: 致命错误:未捕获异常“exception”,消息为“No routes” 在第23行的C:\wamp64\www\todo\core\Router.php中定义此uri 异常:中没有为此uri定义路由 C:\wamp64\www\todo\core\Router.php,第23行 如何通过此错

我正在学习laracast()的本教程,本系列中的这一集(16-制作路由器)。它展示了如何构建一个基本路由器。据我所知,我已经做了视频中所示的所有事情,但我在构建路由器时遇到了问题。 我收到以下错误消息:


致命错误:未捕获异常“exception”,消息为“No routes” 在第23行的C:\wamp64\www\todo\core\Router.php中定义此uri 异常:中没有为此uri定义路由 C:\wamp64\www\todo\core\Router.php,第23行

如何通过此错误?这是我的密码

routes.php:

$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);
如果你需要更多信息,请通知我

更新 这是我在wampserver www文件夹中的网站结构:


我在这门课上也遇到了同样的问题。我相信你已经有htcaccess文件了 里面的代码是什么

RewriteEngine On
RewriteBase /todo/
RewriteRule ^.*$ index.php [END]
无论如何,路线应该是这样的

$router->define([
    'todo' => 'controllers/index.php',
    'todo/about' => 'controllers/about.php',
    'todo/contact' => 'controllers/contact.php'
]);
或者您可以从cmd连接到PHP内置Web服务器,它也将为您解决路由问题


关于

更改错误消息以提供更多信息。也许
“没有为此uri定义路由:$uri”
会告诉您缺少的路由。未捕获的异常“exception”带有消息“No routes define for this uri:todo”,这就是我要了解的,所以您需要将其添加到
routes.php
。很抱歉,响应太晚了。我使用wampserver,在www/目录中有我的项目名todo的根目录,其中有一个index.php,我指定它作为我的应用程序的入口点,如routes.php中的:“”=>“controllers/index.php”。但每当我执行localhost/todo并期望它加载index.php时,它都会返回该错误。