Jinhui Zhu 7 жил өмнө
parent
commit
6022d04948

+ 1 - 0
Qii/Base/Controller.php

@@ -124,6 +124,7 @@ abstract class Controller
         {
             $this->initView();
         }
+        $this->response->setRender($this->view);
         return $this->view ;
     }
 

+ 18 - 3
Qii/Base/Response.php

@@ -10,6 +10,8 @@ class Response
     const FORMAT_JSON = 'json';
     const FORMAT_HTML = 'html';
 
+    public static $render = null;
+
     /**
      * Body content
      * @var array
@@ -39,6 +41,14 @@ class Response
         $this->format = isset($data['format']) ? isset($data['format']) : self::FORMAT_HTML;
 		$this->data = $data;
 	}
+    /**
+     * 设置页面渲染类
+     * @param \Qii\View\Intf $render 渲染类
+     */
+    public function setRender(\Qii\View\Intf $render)
+    {
+        \Qii\Base\Response::$render = $render;
+    }
 
     /**
      * Append content to the body content
@@ -153,10 +163,15 @@ class Response
 						$body = '';
 						if(isset($this->data['body']['render']) && $this->data['body']['render'] instanceof  \Qii\View\Intf)
 						{
-							$tplData = isset($this->data['body']['tplData']) ? $this->data['body']['tplData'] : [];
-							$this->data['body']['render']->assign($tplData);
-							$body = $this->data['body']['render']->fetch($this->data['body']['tpl']);
+                            \Qii\Base\Response::$render = $this->data['body']['render'];
 						}
+
+                        if(\Qii\Base\Response::$render != null && \Qii\Base\Response::$render instanceof  \Qii\View\Intf)
+                        {
+                            $tplData = isset($this->data['body']['tplData']) ? $this->data['body']['tplData'] : [];
+                            \Qii\Base\Response::$render->assign($tplData);
+                            $body = \Qii\Base\Response::$render->fetch($this->data['body']['tpl']);
+                        }
 					}
                     echo (IS_CLI ? (new \Qii\Response\Cli())->stdout($body) : $body);
                 break;