Forked from anonymous/CakePHP1.3_Smarty3_Themeing.php
Created
November 11, 2010 12:09
-
-
Save nerdmom/672398 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* A custom view class that is used for themeing | |
* | |
* PHP versions 4 and 5 | |
* | |
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | |
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
* | |
* Licensed under The MIT License | |
* Redistributions of files must retain the above copyright notice. | |
* | |
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) | |
* @link http://cakephp.org CakePHP(tm) Project | |
* @package cake | |
* @subpackage cake.cake.libs.view | |
* @since CakePHP(tm) v 0.10.0.1076 | |
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) | |
*/ | |
/** | |
* Theme view class | |
* | |
* Allows the creation of multiple themes to be used in an app. Theme views are regular view files | |
* that can provide unique HTML and static assets. If theme views are not found for the current view | |
* the default app view files will be used. You can set `$this->theme` and `$this->view = 'Theme'` | |
* in your Controller to use the ThemeView. | |
* | |
* Example of theme path with `$this->theme = 'super_hot';` Would be `app/views/themed/super_hot/posts` | |
* | |
* @package cake | |
* @subpackage cake.cake.libs.view | |
*/ | |
class ThemeView extends View { | |
public $layout = "layout"; | |
public $ext = ".html"; | |
/** | |
* Constructor for ThemeView sets $this->theme. | |
* | |
* @param Controller $controller | |
*/ | |
function __construct(&$controller, $register = true) { | |
parent::__construct($controller, $register); | |
$this->theme =& $controller->theme; | |
App::import("Vendor", "Smarty", array('file' => 'smarty'.DS.'Smarty.class.php')); | |
$this->Smarty = &new Smarty(); | |
$this->Smarty->plugins_dir[] = VIEWS.'smarty_plugins'.DS; | |
$this->Smarty->compile_dir = TMP.'smarty'.DS.'compile'.DS; | |
$this->Smarty->cache_dir = TMP.'smarty'.DS.'cache'.DS; | |
$this->Smarty->error_reporting = 'E_ALL | E_STRICT'; | |
$this->Smarty->debugging = true; | |
$this->viewVars['params'] = $this->params; | |
} | |
function &_loadHelpers(&$loaded, $helpers, $parent = null) | |
{ | |
$loaded = parent::_loadHelpers($loaded, $helpers, $parent); | |
if( !$parent ) { | |
$prefix = Configure::read("ext_prefix"); | |
foreach(array_keys($loaded) as $helper) { | |
if( strpos($helper, $prefix) !== false) { | |
$loaded[str_replace($prefix, "", $helper)] = $loaded[$helper]; | |
unset($loaded[$helper]); | |
} | |
} | |
} | |
return $loaded; | |
} | |
/** | |
* Renders and returns output for given view filename with its | |
* array of data. | |
* | |
* @param string $___viewFn Filename of the view | |
* @param array $___dataForView Data to include in rendered view | |
* @param boolean $loadHelpers Boolean to indicate that helpers should be loaded. | |
* @param boolean $cached Whether or not to trigger the creation of a cache file. | |
* @return string Rendered output | |
* @access protected | |
*/ | |
function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) { | |
$loadedHelpers = array(); | |
if ($this->helpers != false && $loadHelpers === true) { | |
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers); | |
$helpers = array_keys($loadedHelpers); | |
$helperNames = array_map(array('Inflector', 'variable'), $helpers); | |
for ($i = count($helpers) - 1; $i >= 0; $i--) { | |
$name = $helperNames[$i]; | |
$helper =& $loadedHelpers[$helpers[$i]]; | |
if (!isset($___dataForView[$name])) { | |
${$name} =& $helper; | |
} | |
$this->loaded[$helperNames[$i]] =& $helper; | |
$this->Smarty->assignByRef($name, $helper); | |
} | |
$this->_triggerHelpers('beforeRender'); | |
unset($name, $loadedHelpers, $helpers, $i, $helperNames, $helper); | |
} | |
$this->Smarty->assign($___dataForView); | |
$this->Smarty->assignByRef('view', $this); | |
return $this->Smarty->fetch($___viewFn); | |
} | |
} |
That is how they are written in the original Cake view file class. No special reason other than that! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why the leading underscores on $___viewFn and $___dataForView?