From 136d26a133ce94092200dba0dd795cae64087c08 Mon Sep 17 00:00:00 2001 From: Jasong Zhang <845830229@qq.com> Date: Sun, 4 Jun 2017 23:35:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0views=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Controller.php | 25 +++++++++++++++++++++++++ core/Router.php | 6 ++++-- core/define.php | 5 +++++ views/test/test.php | 9 +++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 views/test/test.php diff --git a/core/Controller.php b/core/Controller.php index 83a2897..8ef7c0c 100755 --- a/core/Controller.php +++ b/core/Controller.php @@ -7,6 +7,17 @@ * Time: 下午4:21 */ class Controller extends Object { + + /** + * @var string controller 名首字母小写 + */ + public $controller; + + /** + * @var string action 名首字母小写 + */ + public $action; + /** * 获取请求组件 * @var object @@ -32,4 +43,18 @@ public function __construct() $this->post = $this->request->post(); $this->get = $this->request->get(); } + + /** + * 视图渲染方法 + * @param string $file + * @param string $value + */ + public function render($file = '',$value = '') + { + if(empty($file)) { + $file = $this->action; + } + extract($value); + require_once (USER_VIEWS_PATH . $this->controller . DS . $file . '.php'); + } } \ No newline at end of file diff --git a/core/Router.php b/core/Router.php index 0d2e978..c2bda46 100755 --- a/core/Router.php +++ b/core/Router.php @@ -44,11 +44,13 @@ public static function distribute($str){ } } $request = new Request(); - $controller = ucfirst(strtolower($request->get('controller'))); + $controller = ucfirst($request->get('controller')); $controllerName = $controller . "Controller"; $object = '\\userController\\' . $controllerName; $object = new $object; - $action = ucfirst(strtolower($request->get('action'))) . "Action"; + $action = ucfirst($request->get('action')) . "Action"; + $object->action = lcfirst($request->get('action')); + $object->controller = lcfirst($request->get('controller')); $object->$action(); } } \ No newline at end of file diff --git a/core/define.php b/core/define.php index 76315e5..9390810 100755 --- a/core/define.php +++ b/core/define.php @@ -26,6 +26,11 @@ */ define('USER_MODEL_PATH' , BASE_PATH . 'userModel' . DS); +/** + * 定义用户视图路径 + */ +define('USER_VIEWS_PATH', BASE_PATH . 'views' . DS); + /** * 定义框架路径 */ diff --git a/views/test/test.php b/views/test/test.php new file mode 100644 index 0000000..cd2be6e --- /dev/null +++ b/views/test/test.php @@ -0,0 +1,9 @@ +hello world + Date: Mon, 5 Jun 2017 18:46:41 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9rendor=E6=96=B9=E6=B3=95?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E4=B9=8B=E7=8B=AC=E7=AB=8B=E6=88=90=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Controller.php | 10 ++++++++-- core/Render.php | 15 +++++++++++++++ core/Request.php | 3 +++ views/layouts/default.php | 12 ++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 core/Render.php create mode 100644 views/layouts/default.php diff --git a/core/Controller.php b/core/Controller.php index 8ef7c0c..6aa6c74 100755 --- a/core/Controller.php +++ b/core/Controller.php @@ -8,6 +8,12 @@ */ class Controller extends Object { + /** + * 控制器layout + * @var string + */ + public $layout = 'default'; + /** * @var string controller 名首字母小写 */ @@ -54,7 +60,7 @@ public function render($file = '',$value = '') if(empty($file)) { $file = $this->action; } - extract($value); - require_once (USER_VIEWS_PATH . $this->controller . DS . $file . '.php'); + $path = USER_VIEWS_PATH . $this->controller . DS . $file . '.php'; + return Render::display($this->layout,$path,$value); } } \ No newline at end of file diff --git a/core/Render.php b/core/Render.php new file mode 100644 index 0000000..bbb9dbe --- /dev/null +++ b/core/Render.php @@ -0,0 +1,15 @@ + + + + + +