关于MVC/路由的php简单实现

http://www.sample.com/index.php/ctr/func/arg

index.php

$script_uri = @$_SERVER['REQUEST_URI'];
$seg = array_slice(explode('/', $script_uri), 2);

$ctr = array_shift($seg);
$func = array_shift($seg);
$arg = array_shift($seg);

require_once($ctr.'.php');
$func($arg);
dog.php
function wow($arg) {
	if(is_array($arg)) {
		print_r($arg);
	} else {
		echo 'dog wow '.$arg;
	}
}

function eat($arg) {
	if(is_array($arg)) {
		print_r($arg);
	} else {
		echo 'dog eat '.$arg;
	}
}

cat.php

function wow($arg) {
	if(is_array($arg)) {
		print_r($arg);
	} else {
		echo 'cat wow '.$arg;
	}
}

function eat($arg) {
	if(is_array($arg)) {
		print_r($arg);
	} else {
		echo 'cat eat '.$arg;
	}
}

request:http://www.sample.com/index.php/dog/eat/bone

response:dog eat bone

request:http://www.sample.com/index.php/cat/wow/mimi

response:cat wow mimi

.

.

.

你可能感兴趣的:(PHP,mvc,路由)