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
This commit is contained in:
phpnut 2005-07-03 07:07:47 +00:00
parent cad49da852
commit 301731fb1a
3 changed files with 31 additions and 23 deletions

View file

@ -279,25 +279,25 @@ class Controller extends Object
function render($action=null, $layout=null, $file=null) function render($action=null, $layout=null, $file=null)
{ {
$v = new View();
$v->_viewVars = $this->_viewVars; $view =& View::getInstance();
$v->action = $this->action; $view->_viewVars =& $this->_viewVars;
$v->autoLayout = $this->autoLayout; $view->action =& $this->action;
$v->autoRender = $this->autoRender; $view->autoLayout =& $this->autoLayout;
$v->base = $this->base; $view->autoRender =& $this->autoRender;
$v->helpers = $this->helpers; $view->base =& $this->base;
$v->here = $this->here; $view->helpers =& $this->helpers;
$v->layout = $this->layout; $view->here =& $this->here;
$v->models = $this->models; $view->layout =& $this->layout;
$v->name = $this->name; $view->models =& $this->models;
$v->pageTitle = $this->pageTitle; $view->name =& $this->name;
$v->parent = $this->parent; $view->pageTitle =& $this->pageTitle;
$v->viewPath = $this->viewPath; $view->parent =& $this->parent;
$view->viewPath =& $this->viewPath;
$v->params = $this->params; $view->params =& $this->params;
$v->data = $this->data; $view->data =& $this->data;
//$this->view = $v;
return $v->render($action, $layout, $file); return $view->render($action, $layout, $file);
} }
function missingController() function missingController()
@ -359,4 +359,4 @@ class Controller extends Object
} }
?> ?>

View file

@ -150,7 +150,7 @@ class Dispatcher extends Object
$controller->params = $params; $controller->params = $params;
$controller->action = $params['action']; $controller->action = $params['action'];
$controller->data = empty($params['data'])? null: $params['data']; $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 // EXECUTE THE REQUESTED ACTION
call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']); call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);

View file

@ -155,13 +155,16 @@ class View extends Object
var $hasRendered = null; var $hasRendered = null;
var $modelsLoaded = false; var $modelsLoaded = false;
function View(){
}
function getInstance() function getInstance()
{ {
static $instance; static $instance;
if (!isset($instance)) if (!isset($instance))
{ {
$instance = array(new View()); $instance[0] =& new View();
} }
return $instance[0]; return $instance[0];
} }
@ -195,6 +198,8 @@ class View extends Object
*/ */
function render($action=null, $layout=null, $file=null) function render($action=null, $layout=null, $file=null)
{ {
if ($this->modelsLoaded!==true) if ($this->modelsLoaded!==true)
{ {
foreach ($this->models as $modelName => $model) foreach ($this->models as $modelName => $model)
@ -202,9 +207,12 @@ class View extends Object
$this->$modelName = $model; $this->$modelName = $model;
} }
} }
// What is reason for these being the same?
if (isset($this->hasRendered) && $this->hasRendered) if (isset($this->hasRendered) && $this->hasRendered)
{ {
//echo "<pre>";
//print_r($this);
//echo "</pre>";
return true; return true;
} }
else else