mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding callback support to elements. You can use the 3rd parameter to control whether or not before/afterRender callbacks should be fired for a particular element.
This commit is contained in:
parent
1b19ad48b4
commit
32587c154c
1 changed files with 9 additions and 1 deletions
|
@ -309,9 +309,11 @@ class View extends Object {
|
|||
* @param string $name Name of template file in the/app/views/elements/ folder
|
||||
* @param array $params Array of data to be made available to the for rendered
|
||||
* view (i.e. the Element)
|
||||
* @param boolean $callbacks Set to true to fire beforeRender and afterRender helper callbacks for this element.
|
||||
* Defaults to false.
|
||||
* @return string Rendered Element
|
||||
*/
|
||||
public function element($name, $params = array(), $loadHelpers = false) {
|
||||
public function element($name, $params = array(), $callbacks = false) {
|
||||
$file = $plugin = $key = null;
|
||||
|
||||
if (isset($params['plugin'])) {
|
||||
|
@ -355,7 +357,13 @@ class View extends Object {
|
|||
if (!$this->_helpersLoaded) {
|
||||
$this->loadHelpers();
|
||||
}
|
||||
if ($callbacks) {
|
||||
$this->Helpers->trigger('beforeRender', array($file));
|
||||
}
|
||||
$element = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
||||
if ($callbacks) {
|
||||
$this->Helpers->trigger('afterRender', array($file, $element));
|
||||
}
|
||||
if (isset($params['cache']) && isset($cacheFile) && isset($expires)) {
|
||||
cache('views' . DS . $cacheFile, $element, $expires);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue