PHP“Rails-like PHP url router”安装程序

时间:2011-08-03 15:00:55

标签: php url-routing

我是新来的,所以我会尽力提出一个好问题。 :)

我正在尝试设置以下PHP URL路由器:http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/

我根据博客文章设置了所有设置,除了“控制器”部分外,它似乎正在工作。请参阅下面的代码:

PHP:

require('includes/class.router.php');

//test controller
class Home {
    public function index(){
        echo "yay, index!!";
    }
}


$r = new Router(); // create router instance 

$r->map('/', array('controller' => 'home')); // main page will call controller "Home" with method "index()"

$r->default_routes(); //send everything else to our default page "home"
$r->execute();

if($r->route_matched) echo "yay, route found for this URL";
    else echo "Sorry, no route found for ths URL. I'm looking for a controller with the following name: " . $r->controller_name;

输出(访问/):

抱歉,找不到该网址的路由。我正在寻找一个名称如下的控制器:Home

2 个答案:

答案 0 :(得分:0)

我可能会误会,但我在路由器中看不到任何“路由匹配”参数?你是说“route_found”吗?如果你测试route_found会发生什么?

答案 1 :(得分:0)

//test controller
class HomeController {
    public function index(){
        echo "yay, index!!";
    }
}

要 HomeControler.php