Fix issue with rendering elements inside blocks.

Fixes exceptions being raised when you tried to render
elements inside blocks.  Instead compare the number of open blocks.
This should not change before/after rendering a view.
This commit is contained in:
mark_story 2011-12-30 14:56:31 -05:00
parent 3478f8a627
commit 6c902a19b3
2 changed files with 17 additions and 5 deletions

View file

@ -827,12 +827,10 @@ class View extends Object {
$data = $this->viewVars;
}
$this->_current = $viewFile;
$initialBlocks = count($this->Blocks->unclosed());
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRenderFile', $this, array($viewFile)));
$content = $this->_evaluate($viewFile, $data);
if ($this->Blocks->active()) {
throw new CakeException(__d('cake_dev', 'The "%s" block was left open.', $this->Blocks->active()));
}
$afterEvent = new CakeEvent('View.afterRenderFile', $this, array($viewFile, $content));
//TODO: For BC puporses, set extra info in the event object. Remove when appropriate
$afterEvent->modParams = 1;
@ -843,11 +841,16 @@ class View extends Object {
$this->_stack[] = $this->fetch('content');
$this->assign('content', $content);
$content = $this->_render($this->_parents[$viewFile], $data);
$content = $this->_render($this->_parents[$viewFile]);
$this->assign('content', array_pop($this->_stack));
}
$remainingBlocks = count($this->Blocks->unclosed());
if ($initialBlocks !== $remainingBlocks) {
throw new CakeException(__d('cake_dev', 'The "%s" block was left open. Blocks are not allowed to cross files.', $this->Blocks->active()));
}
return $content;
}

View file

@ -145,4 +145,13 @@ class ViewBlock {
public function active() {
return end($this->_active);
}
/**
* Get the names of the unclosed/active blocks.
*
* @return array An array of unclosed blocks.
*/
public function unclosed() {
return $this->_active;
}
}