Skip to content

Commit

Permalink
Add accessor method for View properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 18, 2015
1 parent 00d50de commit c1a1a20
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/Controller/Controller.php
Expand Up @@ -317,10 +317,10 @@ public function __get($name)
{
if (in_array($name, ['layout', 'view', 'theme', 'autoLayout', 'viewPath', 'layoutPath'], true)) {
trigger_error(
sprintf('Controller::$%s is deprecated. Use $this->getView()->%s instead.', $name, $name),
sprintf('Controller::$%s is deprecated. Use $this->getView()->%s() instead.', $name, $name),
E_USER_DEPRECATED
);
return $this->getView()->{$name};
return $this->getView()->{$name}();
}

list($plugin, $class) = pluginSplit($this->modelClass, true);
Expand All @@ -341,10 +341,10 @@ public function __set($name, $value)
{
if (in_array($name, ['layout', 'view', 'theme', 'autoLayout', 'viewPath', 'layoutPath'], true)) {
trigger_error(
sprintf('Controller::$%s is deprecated. Use $this->getView()->%s instead.', $name, $name),
sprintf('Controller::$%s is deprecated. Use $this->getView()->%s() instead.', $name, $name),
E_USER_DEPRECATED
);
$this->getView()->{$name} = $value;
$this->getView()->{$name}($value);
return;
}

Expand Down Expand Up @@ -578,9 +578,12 @@ public function render($view = null, $layout = null)
$this->_viewPath();
}
}

$this->autoRender = false;
if ($this->_view->view === null) {
$this->_view->view = isset($this->request->params['action']) ? $this->request->params['action'] : null;
if ($this->_view->view() === null &&
isset($this->request->params['action'])
) {
$this->_view->view($this->request->params['action']);
}

$this->response->body($this->_view->render($view, $layout));
Expand Down
2 changes: 1 addition & 1 deletion src/View/Cell.php
Expand Up @@ -169,7 +169,7 @@ public function render($template = null)
}
$this->_view = null;
$this->View = $this->getView();
$this->_view->layout = false;
$this->_view->layout(false);

$cache = [];
if ($this->_cache) {
Expand Down
48 changes: 48 additions & 0 deletions src/View/View.php
Expand Up @@ -383,6 +383,54 @@ public function autoLayout(bool $autoLayout = null)
$this->layoutPath = $autoLayout;
}

/**
* The view theme to use.
*
* @param string $theme Theme name. If null returns current theme.
* @return string|void
*/
public function theme($theme = null)
{
if ($theme === null) {
return $this->theme;
}

$this->theme = $theme;
}

/**
* Get/set the name of the view file to render. The name specified is the
* filename in /app/Template/<SubFolder> without the .ctp extension.
*
* @param string $name View file name to set. If null returns current name.
* @return string|void
*/
public function view($name = null)
{
if ($name === null) {
return $this->view;
}

$this->view = $name;
}

/**
* Get/set the name of the layout file to render the view inside of.
* The name specified is the filename of the layout in /app/Template/Layout
* without the .ctp extension.
*
* @param string $name Layout file name to set. If null returns current name.
* @return string|void
*/
public function layout($name = null)
{
if ($name === null) {
return $this->layout;
}

$this->layout = $name;
}

/**
* Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
*
Expand Down

0 comments on commit c1a1a20

Please sign in to comment.