赛亿提成统计系统

Route.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/index/id/1 实现get传值
  40. // var_dump($pathArr);
  41. $count = count($pathArr) + 3;
  42. $i = 3;
  43. while ($i < $count){
  44. if (isset($pathArr[$i+1])){
  45. $_GET[$pathArr[$i]] = $pathArr[$i+1];
  46. }
  47. $i = $i + 2;
  48. };
  49. }else{
  50. $this->model = $route['m'];
  51. $this->ctrl = $route['c'];
  52. $this->action = $route['a'];
  53. }
  54. $GLOBALS['model'] = $this->model;
  55. $GLOBALS['ctrl'] = $this->ctrl;
  56. $GLOBALS['action'] = $this->action;
  57. }
  58. }