Skip to content

Commit

Permalink
Adding parameters to helper callbacks, these allow helpers to introsp…
Browse files Browse the repository at this point in the history
…ect more on the view/layout being rendered.

Updating tests.
  • Loading branch information
markstory committed Nov 7, 2010
1 parent 882efa8 commit 1b19ad4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
14 changes: 10 additions & 4 deletions cake/libs/view/helper.php
Expand Up @@ -801,9 +801,10 @@ public function output($str) {
*
* Overridden in subclasses.
*
* @param string $viewFile The view file that is going to be rendered
* @return void
*/
public function beforeRender() {
public function beforeRender($viewFile) {
}

/**
Expand All @@ -812,29 +813,34 @@ public function beforeRender() {
*
* Overridden in subclasses.
*
* @param string $viewFile The view file that was rendered.
* @param string $content The content of the rendered view.
* @return void
*/
public function afterRender() {
public function afterRender($viewFile, $content) {
}

/**
* Before layout callback. beforeLayout is called before the layout is rendered.
*
* Overridden in subclasses.
*
* @param string $layoutFile The layout about to be rendered.
* @return void
*/
public function beforeLayout() {
public function beforeLayout($layoutFile) {
}

/**
* After layout callback. afterLayout is called after the layout has rendered.
*
* Overridden in subclasses.
*
* @param string $layoutFile The layout file that was rendered.
* @param string $content The content of the rendered layout.
* @return void
*/
public function afterLayout() {
public function afterLayout($layoutFile, $content) {
}

/**
Expand Down
4 changes: 2 additions & 2 deletions cake/libs/view/helpers/paginator.php
Expand Up @@ -110,10 +110,10 @@ function __construct(View $View, $settings = array()) {
*
* @return void
*/
public function beforeRender() {
public function beforeRender($viewFile) {
$this->options['url'] = array_merge($this->request->params['pass'], $this->request->params['named']);

parent::beforeRender();
parent::beforeRender($viewFile);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions cake/libs/view/view.php
Expand Up @@ -391,9 +391,9 @@ public function render($action = null, $layout = null, $file = null) {
}

if ($action !== false && $viewFileName = $this->_getViewFileName($action)) {
$this->Helpers->trigger('beforeRender', array($this, $viewFileName));
$this->Helpers->trigger('beforeRender', array($viewFileName));
$out = $this->_render($viewFileName);
$this->Helpers->trigger('afterRender', array($this, $viewFileName, $out));
$this->Helpers->trigger('afterRender', array($viewFileName, $out));
}

if ($layout === null) {
Expand Down Expand Up @@ -437,7 +437,7 @@ public function renderLayout($content_for_layout, $layout = null) {
if (!$this->_helpersLoaded) {
$this->loadHelpers();
}
$this->Helpers->trigger('beforeLayout', array(&$this, $layoutFileName));
$this->Helpers->trigger('beforeLayout', array($layoutFileName));

$this->viewVars = array_merge($this->viewVars, array(
'content_for_layout' => $content_for_layout,
Expand All @@ -454,7 +454,7 @@ public function renderLayout($content_for_layout, $layout = null) {
throw new RuntimeException(sprintf(__("Error in layout %s, got no content."), $layoutFileName));
}

$this->Helpers->trigger('afterLayout', array(&$this, $layoutFileName, $this->output));
$this->Helpers->trigger('afterLayout', array($layoutFileName, $this->output));

return $this->output;
}
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/view/helpers/paginator.test.php
Expand Up @@ -657,7 +657,7 @@ function testPassedArgsMergingWithUrlOptions() {

$this->Paginator->request->params['pass'] = array(2);
$this->Paginator->request->params['named'] = array('foo' => 'bar');
$this->Paginator->beforeRender();
$this->Paginator->beforeRender('posts/index');

$result = $this->Paginator->sort('title');
$expected = array(
Expand Down

0 comments on commit 1b19ad4

Please sign in to comment.