mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Refactoring the Controller::render method, moved the part that constructs the view instance into Controller::_view() for easier overloading this part and better modularization
This commit is contained in:
parent
6ade91e83b
commit
f9d27b6291
1 changed files with 20 additions and 13 deletions
|
@ -930,14 +930,7 @@ class Controller extends Object implements CakeEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
$viewClass = $this->viewClass;
|
||||
if ($this->viewClass != 'View') {
|
||||
list($plugin, $viewClass) = pluginSplit($viewClass, true);
|
||||
$viewClass = $viewClass . 'View';
|
||||
App::uses($viewClass, $plugin . 'View');
|
||||
}
|
||||
|
||||
$View = new $viewClass($this);
|
||||
$this->View = $this->_view();
|
||||
|
||||
$models = ClassRegistry::keys();
|
||||
foreach ($models as $currentModel) {
|
||||
|
@ -946,15 +939,13 @@ class Controller extends Object implements CakeEventListener {
|
|||
$className = get_class($currentObject);
|
||||
list($plugin) = pluginSplit(App::location($className));
|
||||
$this->request->params['models'][$currentObject->alias] = compact('plugin', 'className');
|
||||
$View->validationErrors[$currentObject->alias] =& $currentObject->validationErrors;
|
||||
$this->View->validationErrors[$currentObject->alias] =& $currentObject->validationErrors;
|
||||
}
|
||||
}
|
||||
|
||||
$this->autoRender = false;
|
||||
$this->View = $View;
|
||||
$this->response->body($View->render($view, $layout));
|
||||
return $this->response;
|
||||
}
|
||||
$this->response->body($this->View->render($view, $layout));
|
||||
return $this->response; }
|
||||
|
||||
/**
|
||||
* Returns the referring URL for this request.
|
||||
|
@ -1224,4 +1215,20 @@ class Controller extends Object implements CakeEventListener {
|
|||
return $this->scaffoldError($method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs the view class based on the controllers properties
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
protected function _view() {
|
||||
$viewClass = $this->viewClass;
|
||||
if ($this->viewClass != 'View') {
|
||||
list($plugin, $viewClass) = pluginSplit($viewClass, true);
|
||||
$viewClass = $viewClass . 'View';
|
||||
App::uses($viewClass, $plugin . 'View');
|
||||
}
|
||||
|
||||
return new $viewClass($this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue