You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MvcController.php 1.6 KiB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Util\Controller;
  3. use Util\Util\ViewMode;
  4. class MvcController
  5. {
  6. public $viewModel;//页面模板
  7. public function __construct()
  8. {
  9. $class = get_called_class();
  10. $func = new \ReflectionClass($class);
  11. $viewPath = dirname(dirname($func->getFileName()));
  12. $className = strtolower(str_replace('Controller', '', $func->getShortName()));
  13. $this->viewModel = new ViewMode($viewPath, $className);
  14. }
  15. /**
  16. * Function Description:设置参数
  17. * Function Name: setViewParam
  18. * @param $key
  19. * @param $val
  20. *
  21. *
  22. * @author 倪宗锋
  23. */
  24. public function setViewParam($key, $val)
  25. {
  26. $this->viewModel->setParam($key, $val);
  27. }
  28. /**
  29. * Function Description:设置页面文件路径
  30. * Function Name: setViewUrl
  31. * @param $url
  32. *
  33. *
  34. * @author 倪宗锋
  35. */
  36. public function setViewUrl($url)
  37. {
  38. $this->viewModel->setBaseUrl($url);
  39. }
  40. /**
  41. * Function Description:展示页面
  42. * Function Name: viewModel
  43. * @param string $url
  44. *
  45. * @return string
  46. *
  47. * @author 倪宗锋
  48. */
  49. public function viewModel($url = '')
  50. {
  51. return $this->viewModel->run($url);
  52. }
  53. /**
  54. * Function Description:展示错误信息
  55. * Function Name: viewError
  56. * @param $msg
  57. *
  58. * @return string
  59. *
  60. * @author 倪宗锋
  61. */
  62. public function viewError($msg)
  63. {
  64. $url = ROOT_PATH.'/public/html/error.phtml';
  65. $this->viewModel->setShowUrl($url);
  66. $this->viewModel->setParam('msg', $msg);
  67. $this->viewModel->toUrl();
  68. return '';
  69. }
  70. }