赛亿提成统计系统

Route.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace daswork\lib;
  3. use daswork\lib\Config;
  4. class Route{
  5. public $model; # 模块
  6. public $ctrl; # 控制器
  7. public $action; #方法
  8. public function __construct()
  9. {
  10. //xx.com/index.php/index/index
  11. //xx.com/index/index
  12. /**
  13. * 1.隐藏index.php文件,引入.htaccess文件,与入口文件同级
  14. * 2.获取URL 参数部分,即get传值
  15. * 3.返回对应模块,控制器和方法
  16. */
  17. $route = Config::get('route');
  18. if (isset($_SERVER['PATH_INFO'])&& $_SERVER['PATH_INFO'] != '/'){
  19. $path = $_SERVER['PATH_INFO'];
  20. // var_dump($_SERVER);
  21. // exit;
  22. $pathArr = explode('/',trim($path,'/'));//数组
  23. if (isset($pathArr[0])) {
  24. $this->model = $pathArr[0];
  25. unset($pathArr[0]);
  26. }
  27. if (isset($pathArr[1])){
  28. $this->ctrl = ucfirst(camelize($pathArr[1]));
  29. unset($pathArr[1]);
  30. } else {
  31. $this->ctrl = $route['c'];
  32. }
  33. if (isset($pathArr[2])){
  34. $this->action = camelize($pathArr[2]);
  35. unset($pathArr[2]);
  36. }else{
  37. $this->action = $route['a'];
  38. }
  39. //url 多余部分转换成GET eg:index/index/id/1 实现get传值
  40. $count = count($pathArr) + 2;
  41. $i = 2;
  42. while ($i < $count){
  43. if (isset($pathArr[$i+1])){
  44. $_GET[$pathArr[$i]] = $pathArr[$i+1];
  45. }
  46. $i = $i + 2;
  47. };
  48. }else{
  49. $this->model = $route['m'];
  50. $this->ctrl = $route['c'];
  51. $this->action = $route['a'];
  52. }
  53. $GLOBALS['model'] = $this->model;
  54. $GLOBALS['ctrl'] = $this->ctrl;
  55. $GLOBALS['action'] = $this->action;
  56. }
  57. }