2017-03-17 12 views
1

私はこのチュートリアルを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フォルダに自分のサイトの構造である:

enter image description here

+1

詳細情報を表示するようにエラーメッセージを変更してください。たぶん ''このuriのルートは定義されていません:$ uri "'あなたに欠落しているルートを教えてくれるでしょう。 – miken32

+0

キャッチされない例外メッセージ '例外はこのuri:todoのために定義されていません。' –

+0

これは私が得ているものです。 –

答えて

2

私はこのコースで同じ問題を抱えていました。私はとにかくルートは

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

あるべきか、あなたは内蔵のWebサーバCMDからPHPに接続することができ、それが解決されますあなたは既に

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

内htcaccessファイル 及びこれらのコードを持っているbeleveあなたのためのルートの問題

よろしくお願いします。

関連する問題