From 301731fb1af43e5475685ea5ccb8482cbb7c333e Mon Sep 17 00:00:00 2001 From: phpnut Date: Sun, 3 Jul 2005 07:07:47 +0000 Subject: [PATCH] Corrected the use of View class instance. It looks like the way you where coding it was to be used as a Singleton. In Controller::render() I am setting all View() attributed by pass reference. I do not think it will effect other parts of the system. You can see why I did this by uncommenting the print_r function in View::render(). Reload url in browser. Then in Controller::render() remove the & from: $view->autoRender =& $this->autoRender; This is the only one that seems to cause array to print. This may also caused in the Router::connect(). Look at this if you get time. I noticed that each setting in the conf/routes.php file calls outer::connect(); Tee profiler show this happening 6 times on current install from trunk Router::parse() is called 2 times. We really need to get some good unit test in place. Also speeded things up a little. Profiler test: Before changes on default install from trunk Between: Total Request Time: 13013.4 Milliseconds Total Request Time: 13065.84 Milliseconds 28 files After changes Between: Total Request Time: 10230.99 Milliseconds Total Request Time: 10511.59 Milliseconds 27 files git-svn-id: https://svn.cakephp.org/repo/trunk/cake@304 3807eeeb-6ff5-0310-8944-8be069107fe0 --- libs/controller.php | 40 ++++++++++++++++++++-------------------- libs/dispatcher.php | 2 +- libs/view.php | 12 ++++++++++-- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/libs/controller.php b/libs/controller.php index 4663b2ba4..4e5475f66 100644 --- a/libs/controller.php +++ b/libs/controller.php @@ -279,25 +279,25 @@ class Controller extends Object function render($action=null, $layout=null, $file=null) { - $v = new View(); - $v->_viewVars = $this->_viewVars; - $v->action = $this->action; - $v->autoLayout = $this->autoLayout; - $v->autoRender = $this->autoRender; - $v->base = $this->base; - $v->helpers = $this->helpers; - $v->here = $this->here; - $v->layout = $this->layout; - $v->models = $this->models; - $v->name = $this->name; - $v->pageTitle = $this->pageTitle; - $v->parent = $this->parent; - $v->viewPath = $this->viewPath; - - $v->params = $this->params; - $v->data = $this->data; - //$this->view = $v; - return $v->render($action, $layout, $file); + + $view =& View::getInstance(); + $view->_viewVars =& $this->_viewVars; + $view->action =& $this->action; + $view->autoLayout =& $this->autoLayout; + $view->autoRender =& $this->autoRender; + $view->base =& $this->base; + $view->helpers =& $this->helpers; + $view->here =& $this->here; + $view->layout =& $this->layout; + $view->models =& $this->models; + $view->name =& $this->name; + $view->pageTitle =& $this->pageTitle; + $view->parent =& $this->parent; + $view->viewPath =& $this->viewPath; + $view->params =& $this->params; + $view->data =& $this->data; + + return $view->render($action, $layout, $file); } function missingController() @@ -359,4 +359,4 @@ class Controller extends Object } -?> +?> \ No newline at end of file diff --git a/libs/dispatcher.php b/libs/dispatcher.php index 5f13c0954..4419d763b 100644 --- a/libs/dispatcher.php +++ b/libs/dispatcher.php @@ -150,7 +150,7 @@ class Dispatcher extends Object $controller->params = $params; $controller->action = $params['action']; $controller->data = empty($params['data'])? null: $params['data']; - //$controller->passed_args = empty($params['pass'])? null: $params['pass']; + $controller->passed_args = empty($params['pass'])? null: $params['pass']; // EXECUTE THE REQUESTED ACTION call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']); diff --git a/libs/view.php b/libs/view.php index 52ecb60ad..ef4c98747 100644 --- a/libs/view.php +++ b/libs/view.php @@ -155,13 +155,16 @@ class View extends Object var $hasRendered = null; var $modelsLoaded = false; + + function View(){ + } function getInstance() { static $instance; if (!isset($instance)) { - $instance = array(new View()); + $instance[0] =& new View(); } return $instance[0]; } @@ -195,6 +198,8 @@ class View extends Object */ function render($action=null, $layout=null, $file=null) { + + if ($this->modelsLoaded!==true) { foreach ($this->models as $modelName => $model) @@ -202,9 +207,12 @@ class View extends Object $this->$modelName = $model; } } - + // What is reason for these being the same? if (isset($this->hasRendered) && $this->hasRendered) { + //echo "
";
+		//print_r($this);
+		//echo "
"; return true; } else