drnrxv9383 2017-03-17 17:25
浏览 44
已采纳

此uri没有定义路由

I’m following this tutorial from laracast(https://laracasts.com/series/php-for-beginners) and I’m at this episode(16 - Make a Router) in the series. Which shows how to build a basic router. I have done everthing to my knowledge as illustrated in the video, but I’m experiencing problems with building the router. I’m getting this error message:

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

How do I get passed this error? Here are my codes

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);

If you need more information inform me.

UPDATE This is my site structure in wampserver www folder:

enter image description here

  • 写回答

1条回答 默认 最新

  • dtmjqyfz21793 2017-07-02 19:41
    关注

    I had the same problem in this course. I beleve you already have htcaccess file and these codes inside

    RewriteEngine On
    RewriteBase /todo/
    RewriteRule ^.*$ index.php [END]
    

    Anyway the routes should be like this

    $router->define([
        'todo' => 'controllers/index.php',
        'todo/about' => 'controllers/about.php',
        'todo/contact' => 'controllers/contact.php'
    ]);
    

    or you can connect to PHP built-in Web Server from cmd, it will solve route issue for you as well

    Regards

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路