mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Merge pull request #1086 from burzum/refactor/controller-render
Refactoring the Controller::render method Create Controller::_getViewObject() which is responsible for creating the view instance. This gives an easier way to override view construction.
This commit is contained in:
commit
7a184708fc
1 changed files with 19 additions and 11 deletions
|
@ -930,14 +930,7 @@ class Controller extends Object implements CakeEventListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$viewClass = $this->viewClass;
|
$this->View = $this->_getViewObject();
|
||||||
if ($this->viewClass != 'View') {
|
|
||||||
list($plugin, $viewClass) = pluginSplit($viewClass, true);
|
|
||||||
$viewClass = $viewClass . 'View';
|
|
||||||
App::uses($viewClass, $plugin . 'View');
|
|
||||||
}
|
|
||||||
|
|
||||||
$View = new $viewClass($this);
|
|
||||||
|
|
||||||
$models = ClassRegistry::keys();
|
$models = ClassRegistry::keys();
|
||||||
foreach ($models as $currentModel) {
|
foreach ($models as $currentModel) {
|
||||||
|
@ -946,13 +939,12 @@ class Controller extends Object implements CakeEventListener {
|
||||||
$className = get_class($currentObject);
|
$className = get_class($currentObject);
|
||||||
list($plugin) = pluginSplit(App::location($className));
|
list($plugin) = pluginSplit(App::location($className));
|
||||||
$this->request->params['models'][$currentObject->alias] = compact('plugin', '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->autoRender = false;
|
||||||
$this->View = $View;
|
$this->response->body($this->View->render($view, $layout));
|
||||||
$this->response->body($View->render($view, $layout));
|
|
||||||
return $this->response;
|
return $this->response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1224,4 +1216,20 @@ class Controller extends Object implements CakeEventListener {
|
||||||
return $this->scaffoldError($method);
|
return $this->scaffoldError($method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs the view class instance based on the controller property
|
||||||
|
*
|
||||||
|
* @return View
|
||||||
|
*/
|
||||||
|
protected function _getViewObject() {
|
||||||
|
$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…
Add table
Reference in a new issue