[php]代码库
<?php
/**
* 框架主入口文件,所有的页面请求均定为到该页面,并根据 url 地址来确定调用合适的方法并显示输出
*/
define('APPPATH', '');
// 自动加载所需的类
require('core/Common.php');
// 加载 core/URI.php 类
$URI =& load_class('URI');
// 加载 core/Router.php 类
$RTR =& load_class('Router');
// 调用 Router.php 类的 set_routing() 方法,抽取路由信息
$RTR->set_routing();
// 抽取路由中的 class 名与 method 名
$class = $RTR->fetch_class();
$method = $RTR->fetch_method();
// 加载 core/Controller.php 类
require('core/Controller.php');
function &get_instance() {
return CI_Controller::get_instance();
}
// 根据 class 名加载控制器
require('controllers/'.$class.'.php');
// new 一个控制器的对象,$class 就是控制器的名
$CI = new $class();
/*
echo '<pre>';
print_r( $URI->rsegments );
print_r(array(&$CI, $method));
print_r(array_slice($URI->rsegments, 2));
echo '</pre>';
*/
call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 1));
//call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));
-----------------------
Class ClassA
{
function bc($b, $c) {
$bc = $b + $c;
echo $bc;
}
}
call_user_func_array(array('ClassA','bc'), array("111", "222"));
//显示 333
Array
(
[0] => welcome Object
(
[uri] => CI_URI Object
(
[segments] => Array
(
[0] => welcome
[1] => nowamagic
)
[uri_string] => welcome/nowamagic
[rsegments] => Array
(
[0] => welcome
[1] => nowamagic
)
)
[router] => CI_Router Object
(
[uri] => CI_URI Object
(
[segments] => Array
(
[0] => welcome
[1] => nowamagic
)
[uri_string] => welcome/nowamagic
[rsegments] => Array
(
[0] => welcome
[1] => nowamagic
)
)
[routes] => Array
(
[default_controller] => home
[welcome/nowamagic] => welcome/nowamagic
)
[class] => welcome
[method] => nowamagic
[default_controller] => home
)
[load] => CI_Loader Object
(
[_ci_model_paths:protected] => Array
(
[0] =>
)
[_ci_models:protected] => Array
(
)
)
)
[1] => nowamagic
)