首先看一下现有的文件目录

DOCUMENT_ROOR 为 /home/www目录

然后看一下入口文件的内容

<?php$controll_action = $_GET['_ca_'];$params  = explode('/',$controll_action);$params_count = count($params);$otherParams = $params;if($params_count>1) {$controller = $params[0];$action  = $params[1];unset($params[0]);unset($params[1]);}else if($params_count==1) {$controller = $params[0];$action = 'index';unset($params[0]);}$filename = strtolower($controller).'.php';$controller_path = $_SERVER['DOCUMENT_ROOT'].'/application/controllers/';if(!file_exists($controller_path.$filename)) {throw new Exception('controller '.$filename.' is not exists!');return;}include($controller_path.$filename);$classname = ucfirst($controller);if(!class_exists($classname)) {throw new Excpetion('class '.$classname.' is not exists!');}$reflecObj = new ReflectionClass($classname);if(!$reflecObj->hasMethod($action)){throw new Exception('method '.$action.' is not exists!');}$currentObj = new $classname();echo "classname=$classname,action=$action,params=".json_encode($params)."<br/>";call_user_func_array([$currentObj,$action],$params);return;?>

然后创建一个简单的控制器 user.php,放到applicaiton/controllers/目录下,具体内容如下:

<?phpclass User {        function __construct(){            }    public function index($name='')    {    echo 'hello,'.$name.',lucky,you are arrive here!';    }}

最后测试一个正确的控制器跳转和错误的控制器跳转

首先测试一下正确的流程: http://192.168.1.99/user/index/xiaoming

输出内容:

classname=User,action=index,params={"2":"xiaoming"} hello,xiaoming,lucky,you are arrive here!

再测试一下不存在的控制器,http://192.168.1.99/account/index/xiaoming

Fatal error: Uncaught exception 'Exception' with message 'controller acount.php is not exists!' in /home/www/webroot/index.php:25Stack trace:#0 {main} thrown in /home/www/webroot/index.php on line 25

更多相关文章

  1. 一个查看xhprof数据文件的docker镜像
  2. 教你用php读写csv格式的文件
  3. web安全之文件上传漏洞攻击与防范方法
  4. 使用file_get_contents()函数读取文件内容
  5. php文件后缀名是什么
  6. 如何对php文件加密

随机推荐

  1. android相机预览
  2. Android学习_android镜像
  3. android之修改系统自带ProgressDialog样
  4. 使用android studio中遇到的常见问题及解
  5. 【Android(安卓)Native Code开发系列】三
  6. Android Toast 使用总结
  7. 创建 cocos2d-x+lua for android 步骤
  8. Must specify unique android:id, androi
  9. android 中超出屏幕宽度的字符 省略号显
  10. Android中手机声音调节步骤(Android学习随