|
- <?php
- namespace Util\Controller;
-
- use Util\Util\ViewMode;
-
- class MvcController
- {
- public $viewModel;//页面模板
-
- public function __construct()
- {
- $class = get_called_class();
- $func = new \ReflectionClass($class);
- $viewPath = dirname(dirname($func->getFileName()));
- $className = strtolower(str_replace('Controller', '', $func->getShortName()));
- $this->viewModel = new ViewMode($viewPath, $className);
- }
-
- /**
- * Function Description:设置参数
- * Function Name: setViewParam
- * @param $key
- * @param $val
- *
- *
- * @author 倪宗锋
- */
- public function setViewParam($key, $val)
- {
- $this->viewModel->setParam($key, $val);
- }
-
- /**
- * Function Description:设置页面文件路径
- * Function Name: setViewUrl
- * @param $url
- *
- *
- * @author 倪宗锋
- */
- public function setViewUrl($url)
- {
- $this->viewModel->setBaseUrl($url);
- }
-
- /**
- * Function Description:展示页面
- * Function Name: viewModel
- * @param string $url
- *
- * @return string
- *
- * @author 倪宗锋
- */
- public function viewModel($url = '')
- {
- return $this->viewModel->run($url);
- }
-
- /**
- * Function Description:展示错误信息
- * Function Name: viewError
- * @param $msg
- *
- * @return string
- *
- * @author 倪宗锋
- */
- public function viewError($msg)
- {
- $url = ROOT_PATH.'/public/html/error.phtml';
- $this->viewModel->setShowUrl($url);
- $this->viewModel->setParam('msg', $msg);
- $this->viewModel->toUrl();
- return '';
- }
- }
|