Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

enabling view hook from plugin

  • Loading branch information...
commit cf97da21056fb191806bbdb329a238c686ab5a79 1 parent 1b0746b
@yandod yandod authored
Showing with 13 additions and 70 deletions.
  1. +1 −1  app/Controller/AppController.php
  2. +12 −69 app/View/CandyView.php
View
2  app/Controller/AppController.php
@@ -30,7 +30,7 @@ class AppController extends Controller {
public $per_page;
- public $view = 'Candy';
+ public $viewClass = 'Candy';
public $theme = '';
View
81 app/View/CandyView.php
@@ -1,76 +1,19 @@
<?php
-App::import('View','Theme');
-class CandyView extends ThemeView {
-
- public function __construct (&$controller) {
- parent::__construct($controller);
- }
-
- function element($name, $params = array(), $loadHelpers = false) {
- $file = $plugin = $key = null;
-
- if (isset($params['plugin'])) {
- $plugin = $params['plugin'];
- }
-
- if (isset($this->plugin) && !$plugin) {
- $plugin = $this->plugin;
- }
-
- if (isset($params['cache'])) {
- $expires = '+1 day';
-
- if (is_array($params['cache'])) {
- $expires = $params['cache']['time'];
- $key = Inflector::slug($params['cache']['key']);
- } elseif ($params['cache'] !== true) {
- $expires = $params['cache'];
- $key = implode('_', array_keys($params));
- }
-
- if ($expires) {
- $cacheFile = 'element_' . $key . '_' . $plugin . Inflector::slug($name);
- $cache = cache('views' . DS . $cacheFile, null, $expires);
-
- if (is_string($cache)) {
- return $cache;
- }
- }
- }
- $paths = $this->_paths($plugin);
-
- foreach ($paths as $path) {
- if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
- $file = $path . 'elements' . DS . $name . $this->ext;
- break;
- } elseif (file_exists($path . 'elements' . DS . $name . '.thtml')) {
- $file = $path . 'elements' . DS . $name . '.thtml';
- break;
- }
- }
-
+class CandyView extends View {
+ function element($name, $data = array(), $options = false) {
+
+ $element = parent::element($name, $data, $options);
+
$hookContainer = ClassRegistry::getObject('HookContainer');
- if (is_file($file)) {
- $params = array_merge_recursive($params, $this->loaded);
- $before = "";
- if ($hookContainer->getElementHook($name,true)) {
- $before = $this->element($hookContainer->getElementHook($name,true), array(), $loadHelpers);
- }
- $element = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
- $after = "";
- if ($hookContainer->getElementHook($name)) {
- $after = $this->element($hookContainer->getElementHook($name), array(), $loadHelpers);
- }
- if (isset($params['cache']) && isset($cacheFile) && isset($expires)) {
- cache('views' . DS . $cacheFile, $element, $expires);
- }
- return $before.$element.$after;
+ $before = "";
+ if ($hookContainer->getElementHook($name,true)) {
+ $before = $this->element($hookContainer->getElementHook($name,true), $data, $options);
}
- $file = $paths[0] . 'elements' . DS . $name . $this->ext;
-
- if (Configure::read('debug') > 0) {
- return "Not Found: " . $file;
+ $after = "";
+ if ($hookContainer->getElementHook($name)) {
+ $after = $this->element($hookContainer->getElementHook($name), $data, $options);
}
+ return $before.$element.$after;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.