开发者

PHP "Rails-like PHP url router" Setup

开发者 https://www.devze.com 2023-03-25 04:39 出处:网络
I\'m new here so I\'ll try my best to make a good question. :) I\'m trying to setup the following PHP URL Router: http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/

I'm new here so I'll try my best to make a good question. :)

I'm trying to setup the following PHP URL Router: http://blog.sosedoff.com/2009/09/20/rails-like-php-url-router/

I have everything setup based off the blog post and it seems to be working except for the "controller" part. Please see my code below:

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 foll开发者_StackOverflowowing name: " . $r->controller_name;

Output (accessing /):

Sorry, no route found for ths URL. I'm looking for a controller with the following name: Home


I might be mistaking, but I don't see any "route_matched" paramtere within the Router? Did you mean "route_found"? What happens if you test for route_found?


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

to HomeControler.php

0

精彩评论

暂无评论...
验证码 换一张
取 消