我正在从laracast( https://laracasts.com/series/php-for-beginners )关注本教程,我正在本系列中的这一集(16 - Make a Router)。 其中显示了如何构建基本路由器。 我已经完成了我的知识,如视频中所示,但我遇到了构建路由器的问题。 我收到此错误消息:
致命错误:第23行的C:\ wamp64 \ www \ todo \ core \ Router.php消息'没有为此uri定义路由'的未捕获异常'异常'例外:在C:\ wamp64 \中没有为此uri定义路由第23行的www \ todo \ core \ Router.php
我如何通过此错误? 这是我的代码
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文件夹中的网站结构:
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:
最满意答案
我在这门课程中遇到了同样的问题。 我觉得你已经有了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服务器,它也将为您解决路由问题
问候
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
更多推荐
发布评论