2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Methods for displaying presentation data in the view.
|
|
|
|
*
|
2010-07-02 02:47:20 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view
|
|
|
|
* @since CakePHP(tm) v 0.10.0.1076
|
2009-11-06 06:51:51 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Included libraries.
|
|
|
|
*/
|
2010-12-03 23:07:21 +00:00
|
|
|
App::uses('HelperCollection', 'View');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* View, the V in the MVC triad.
|
|
|
|
*
|
|
|
|
* Class holding methods for displaying presentation data.
|
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs.view
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class View extends Object {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-03 03:50:41 +00:00
|
|
|
/**
|
|
|
|
* Helpers collection
|
|
|
|
*
|
|
|
|
* @var HelperCollection
|
|
|
|
*/
|
|
|
|
public $Helpers;
|
2010-07-15 03:14:39 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Name of the plugin.
|
|
|
|
*
|
2010-04-24 04:22:21 +00:00
|
|
|
* @link http://manual.cakephp.org/chapter/plugins
|
2008-05-30 11:40:08 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $plugin = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Name of the controller.
|
|
|
|
*
|
|
|
|
* @var string Name of controller
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $name = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Current passed params
|
|
|
|
*
|
|
|
|
* @var mixed
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $passedArgs = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* An array of names of built-in helpers to include.
|
|
|
|
*
|
|
|
|
* @var mixed A single name as a string or a list of names as an array.
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $helpers = array('Html');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Path to View.
|
|
|
|
*
|
|
|
|
* @var string Path to View
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $viewPath = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Variables for the view
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $viewVars = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Name of layout to use with this View.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $layout = 'default';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Path to Layout.
|
|
|
|
*
|
|
|
|
* @var string Path to Layout
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $layoutPath = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Turns on or off Cake's conventional mode of rendering views. On by default.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $autoRender = true;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Turns on or off Cake's conventional mode of finding layout files. On by default.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $autoLayout = true;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* File extension. Defaults to Cake's template ".ctp".
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $ext = '.ctp';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Sub-directory for this view file.
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $subDir = null;
|
2009-11-25 07:51:25 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Theme name.
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $theme = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Used to define methods a controller that will be cached.
|
|
|
|
*
|
|
|
|
* @see Controller::$cacheAction
|
|
|
|
* @var mixed
|
|
|
|
* @access public
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $cacheAction = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* holds current errors for the model validation
|
|
|
|
*
|
|
|
|
* @var array
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $validationErrors = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* True when the view has been rendered.
|
|
|
|
*
|
|
|
|
* @var boolean
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $hasRendered = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* True if in scope of model-specific region
|
|
|
|
*
|
|
|
|
* @var boolean
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $modelScope = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Name of current model this view context is attached to
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $model = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Name of association model this view context is attached to
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $association = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Name of current model field this view context is attached to
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $field = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Suffix of current field this view context is attached to
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $fieldSuffix = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* The current model ID this view context is attached to
|
|
|
|
*
|
|
|
|
* @var mixed
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $modelId = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* List of generated DOM UUIDs
|
|
|
|
*
|
|
|
|
* @var array
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $uuids = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds View output.
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access public
|
2009-11-14 12:19:25 +00:00
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $output = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-09-11 03:55:42 +00:00
|
|
|
/**
|
|
|
|
* An instance of a CakeRequest object that contains information about the current request.
|
|
|
|
* This object contains all the information about a request and several methods for reading
|
|
|
|
* additional information about the request.
|
|
|
|
*
|
|
|
|
* @var CakeRequest
|
|
|
|
*/
|
|
|
|
public $request;
|
|
|
|
|
2010-11-10 03:16:45 +00:00
|
|
|
/**
|
|
|
|
* The Cache configuration View will use to store cached elements. Changing this will change
|
|
|
|
* the default configuration elements are stored under. You can also choose a cache config
|
|
|
|
* per element.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @see View::element()
|
|
|
|
*/
|
|
|
|
public $elementCache = 'default';
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* List of variables to collect from the associated controller
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @access protected
|
|
|
|
*/
|
2010-04-04 06:33:39 +00:00
|
|
|
private $__passedVars = array(
|
2010-09-11 03:55:42 +00:00
|
|
|
'viewVars', 'autoLayout', 'autoRender', 'ext', 'helpers', 'layout', 'name',
|
|
|
|
'layoutPath', 'viewPath', 'request', 'plugin', 'passedArgs', 'cacheAction'
|
2008-11-09 03:20:14 +00:00
|
|
|
);
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Scripts (and/or other <head /> tags) for the layout
|
|
|
|
*
|
|
|
|
* @var array
|
2010-04-05 11:15:17 +00:00
|
|
|
* @access protected
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 11:15:17 +00:00
|
|
|
protected $_scripts = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Holds an array of paths.
|
|
|
|
*
|
|
|
|
* @var array
|
2010-01-25 23:14:16 +00:00
|
|
|
* @access private
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-04 06:33:39 +00:00
|
|
|
private $__paths = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-11-05 02:29:41 +00:00
|
|
|
/**
|
|
|
|
* boolean to indicate that helpers have been loaded.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $_helpersLoaded = false;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
2010-01-25 23:14:16 +00:00
|
|
|
* @param Controller $controller A controller object to pull View::__passedArgs from.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-11-13 03:51:53 +00:00
|
|
|
function __construct($controller) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_object($controller)) {
|
|
|
|
$count = count($this->__passedVars);
|
|
|
|
for ($j = 0; $j < $count; $j++) {
|
|
|
|
$var = $this->__passedVars[$j];
|
|
|
|
$this->{$var} = $controller->{$var};
|
|
|
|
}
|
|
|
|
}
|
2010-07-03 03:50:41 +00:00
|
|
|
$this->Helpers = new HelperCollection($this);
|
2008-05-30 11:40:08 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders a piece of PHP with provided parameters and returns HTML, XML, or any other string.
|
|
|
|
*
|
|
|
|
* This realizes the concept of Elements, (or "partial layouts")
|
|
|
|
* and the $params array is used to send data to be used in the
|
2008-08-03 05:24:10 +00:00
|
|
|
* Element. Elements can be cached through use of the cache key.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-08-20 05:20:13 +00:00
|
|
|
* ### Special params
|
|
|
|
*
|
2010-11-10 03:16:45 +00:00
|
|
|
* - `cache` - Can either be `true`, to enable caching using the config in View::$elementCache. Or an array
|
|
|
|
* If an array, the following keys can be used:
|
|
|
|
* - `config` - Used to store the cached element in a custom cache configuration.
|
|
|
|
* - `key` - Used to define the key used in the Cache::write(). It will be prefixed with `element_`
|
2010-01-25 23:14:16 +00:00
|
|
|
* - `plugin` - Load an element from a specific plugin.
|
2009-08-20 05:20:13 +00:00
|
|
|
*
|
2008-05-30 11:40:08 +00:00
|
|
|
* @param string $name Name of template file in the/app/views/elements/ folder
|
2008-11-09 03:20:14 +00:00
|
|
|
* @param array $params Array of data to be made available to the for rendered
|
2009-08-20 05:20:13 +00:00
|
|
|
* view (i.e. the Element)
|
2010-11-05 03:32:18 +00:00
|
|
|
* @param boolean $callbacks Set to true to fire beforeRender and afterRender helper callbacks for this element.
|
|
|
|
* Defaults to false.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Rendered Element
|
|
|
|
*/
|
2010-11-05 03:32:18 +00:00
|
|
|
public function element($name, $params = array(), $callbacks = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$file = $plugin = $key = null;
|
|
|
|
|
|
|
|
if (isset($params['plugin'])) {
|
|
|
|
$plugin = $params['plugin'];
|
|
|
|
}
|
|
|
|
if (isset($this->plugin) && !$plugin) {
|
|
|
|
$plugin = $this->plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($params['cache'])) {
|
2010-11-10 03:27:36 +00:00
|
|
|
$keys = array_merge(array($plugin, $name), array_keys($params));
|
|
|
|
$caching = array(
|
|
|
|
'config' => $this->elementCache,
|
|
|
|
'key' => implode('_', $keys)
|
|
|
|
);
|
2008-05-30 11:40:08 +00:00
|
|
|
if (is_array($params['cache'])) {
|
2010-11-08 05:05:44 +00:00
|
|
|
$defaults = array(
|
2010-11-10 03:16:45 +00:00
|
|
|
'config' => $this->elementCache,
|
2010-11-10 03:27:36 +00:00
|
|
|
'key' => $caching['key']
|
2010-11-08 05:05:44 +00:00
|
|
|
);
|
|
|
|
$caching = array_merge($defaults, $params['cache']);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-11-10 03:16:45 +00:00
|
|
|
$key = 'element_' . $caching['key'];
|
2010-11-08 05:05:44 +00:00
|
|
|
$contents = Cache::read($key, $caching['config']);
|
|
|
|
if ($contents !== false) {
|
|
|
|
return $contents;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-10 03:16:45 +00:00
|
|
|
$file = $this->_getElementFilename($name, $plugin);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-10 03:16:45 +00:00
|
|
|
if ($file) {
|
2010-11-05 02:29:41 +00:00
|
|
|
if (!$this->_helpersLoaded) {
|
|
|
|
$this->loadHelpers();
|
|
|
|
}
|
2010-11-05 03:32:18 +00:00
|
|
|
if ($callbacks) {
|
|
|
|
$this->Helpers->trigger('beforeRender', array($file));
|
|
|
|
}
|
2010-11-05 03:45:07 +00:00
|
|
|
$element = $this->_render($file, array_merge($this->viewVars, $params));
|
2010-11-05 03:32:18 +00:00
|
|
|
if ($callbacks) {
|
|
|
|
$this->Helpers->trigger('afterRender', array($file, $element));
|
|
|
|
}
|
2010-11-08 05:05:44 +00:00
|
|
|
if (isset($params['cache'])) {
|
|
|
|
Cache::write($key, $element, $caching['config']);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
return $element;
|
|
|
|
}
|
2010-11-10 03:16:45 +00:00
|
|
|
$file = 'elements' . DS . $name . $this->ext;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-07-06 01:50:36 +00:00
|
|
|
if (Configure::read('debug') > 0) {
|
2010-11-10 03:16:45 +00:00
|
|
|
return "Element Not Found: " . $file;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders view for given action and layout. If $file is given, that is used
|
|
|
|
* for a view filename (e.g. customFunkyView.ctp).
|
|
|
|
*
|
|
|
|
* @param string $action Name of action to render for
|
|
|
|
* @param string $layout Layout to use
|
|
|
|
* @param string $file Custom filename for view
|
|
|
|
* @return string Rendered Element
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function render($action = null, $layout = null, $file = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($this->hasRendered) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-11-05 02:29:41 +00:00
|
|
|
if (!$this->_helpersLoaded) {
|
|
|
|
$this->loadHelpers();
|
|
|
|
}
|
2010-11-05 03:50:59 +00:00
|
|
|
$this->output = null;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if ($file != null) {
|
|
|
|
$action = $file;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($action !== false && $viewFileName = $this->_getViewFileName($action)) {
|
2010-11-05 02:53:00 +00:00
|
|
|
$this->Helpers->trigger('beforeRender', array($viewFileName));
|
2010-11-05 03:50:59 +00:00
|
|
|
$this->output = $this->_render($viewFileName);
|
2010-11-05 03:55:50 +00:00
|
|
|
$this->Helpers->trigger('afterRender', array($viewFileName));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($layout === null) {
|
|
|
|
$layout = $this->layout;
|
|
|
|
}
|
2010-11-05 03:50:59 +00:00
|
|
|
if ($this->output === false) {
|
2010-11-05 02:36:37 +00:00
|
|
|
throw new RuntimeException(sprintf(__("Error in view %s, got no content."), $viewFileName));
|
|
|
|
}
|
|
|
|
if ($layout && $this->autoLayout) {
|
2010-11-05 03:50:59 +00:00
|
|
|
$this->output = $this->renderLayout($this->output, $layout);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-11-05 02:36:37 +00:00
|
|
|
$this->hasRendered = true;
|
2010-11-05 03:50:59 +00:00
|
|
|
return $this->output;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Renders a layout. Returns output from _render(). Returns false on error.
|
2008-08-03 05:24:10 +00:00
|
|
|
* Several variables are created for use in layout.
|
2009-08-20 05:15:08 +00:00
|
|
|
*
|
2010-03-28 16:53:57 +00:00
|
|
|
* - `title_for_layout` - A backwards compatible place holder, you should set this value if you want more control.
|
2009-08-20 05:15:08 +00:00
|
|
|
* - `content_for_layout` - contains rendered view file
|
|
|
|
* - `scripts_for_layout` - contains scripts added to header
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
|
|
|
|
* @return mixed Rendered output, or false on error
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function renderLayout($content_for_layout, $layout = null) {
|
2008-10-23 00:10:44 +00:00
|
|
|
$layoutFileName = $this->_getLayoutFileName($layout);
|
2009-07-21 01:33:12 +00:00
|
|
|
if (empty($layoutFileName)) {
|
|
|
|
return $this->output;
|
|
|
|
}
|
2010-11-05 02:29:41 +00:00
|
|
|
if (!$this->_helpersLoaded) {
|
|
|
|
$this->loadHelpers();
|
|
|
|
}
|
2010-11-05 02:53:00 +00:00
|
|
|
$this->Helpers->trigger('beforeLayout', array($layoutFileName));
|
2009-07-21 01:33:12 +00:00
|
|
|
|
2010-11-01 03:15:34 +00:00
|
|
|
$this->viewVars = array_merge($this->viewVars, array(
|
2008-11-09 03:37:24 +00:00
|
|
|
'content_for_layout' => $content_for_layout,
|
2010-04-05 11:15:17 +00:00
|
|
|
'scripts_for_layout' => implode("\n\t", $this->_scripts),
|
2008-11-09 03:37:24 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-01 03:15:34 +00:00
|
|
|
if (!isset($this->viewVars['title_for_layout'])) {
|
|
|
|
$this->viewVars['title_for_layout'] = Inflector::humanize($this->viewPath);
|
2009-09-29 01:23:40 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-05 02:29:41 +00:00
|
|
|
$this->output = $this->_render($layoutFileName);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if ($this->output === false) {
|
2010-11-05 02:36:37 +00:00
|
|
|
throw new RuntimeException(sprintf(__("Error in layout %s, got no content."), $layoutFileName));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2010-11-05 02:29:41 +00:00
|
|
|
|
2010-11-05 03:55:50 +00:00
|
|
|
$this->Helpers->trigger('afterLayout', array($layoutFileName));
|
2008-11-24 05:36:06 +00:00
|
|
|
return $this->output;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2010-01-25 23:14:16 +00:00
|
|
|
* Render cached view. Works in concert with CacheHelper and Dispatcher to
|
|
|
|
* render cached view files.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* @param string $filename the cache file to include
|
|
|
|
* @param string $timeStart the page render start time
|
2010-01-25 23:14:16 +00:00
|
|
|
* @return boolean Success of rendering the cached file.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function renderCache($filename, $timeStart) {
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
include ($filename);
|
|
|
|
|
2010-07-06 01:50:36 +00:00
|
|
|
if (Configure::read('debug') > 0 && $this->layout != 'xml') {
|
2010-04-15 16:58:28 +00:00
|
|
|
echo "<!-- Cached Render Time: " . round(microtime(true) - $timeStart, 4) . "s -->";
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match)) {
|
|
|
|
if (time() >= $match['1']) {
|
|
|
|
@unlink($filename);
|
|
|
|
unset ($out);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
if ($this->layout === 'xml') {
|
|
|
|
header('Content-type: text/xml');
|
|
|
|
}
|
2009-09-15 03:56:50 +00:00
|
|
|
$commentLength = strlen('<!--cachetime:' . $match['1'] . '-->');
|
|
|
|
echo substr($out, $commentLength);
|
2008-05-30 11:40:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of variables available in the current View context
|
|
|
|
*
|
2010-01-25 23:14:16 +00:00
|
|
|
* @return array Array of the set view variable names.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function getVars() {
|
2008-05-30 11:40:08 +00:00
|
|
|
return array_keys($this->viewVars);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the contents of the given View variable(s)
|
|
|
|
*
|
2010-01-25 23:14:16 +00:00
|
|
|
* @param string $var The view var you want the contents of.
|
|
|
|
* @return mixed The content of the named var if its set, otherwise null.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function getVar($var) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (!isset($this->viewVars[$var])) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return $this->viewVars[$var];
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Adds a script block or other element to be inserted in $scripts_for_layout in
|
2010-01-25 23:14:16 +00:00
|
|
|
* the `<head />` of a document layout
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-01-25 23:14:16 +00:00
|
|
|
* @param string $name Either the key name for the script, or the script content. Name can be used to
|
|
|
|
* update/replace a script element.
|
|
|
|
* @param string $content The content of the script being added, optional.
|
2008-08-03 05:24:10 +00:00
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function addScript($name, $content = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (empty($content)) {
|
2010-04-05 11:15:17 +00:00
|
|
|
if (!in_array($name, array_values($this->_scripts))) {
|
|
|
|
$this->_scripts[] = $name;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-04-05 11:15:17 +00:00
|
|
|
$this->_scripts[$name] = $content;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Generates a unique, non-random DOM ID for an object, based on the object type and the target URL.
|
|
|
|
*
|
|
|
|
* @param string $object Type of object, i.e. 'form' or 'link'
|
|
|
|
* @param string $url The object's target URL
|
|
|
|
* @return string
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function uuid($object, $url) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$c = 1;
|
|
|
|
$url = Router::url($url);
|
|
|
|
$hash = $object . substr(md5($object . $url), 0, 10);
|
|
|
|
while (in_array($hash, $this->uuids)) {
|
|
|
|
$hash = $object . substr(md5($object . $url . $c), 0, 10);
|
|
|
|
$c++;
|
|
|
|
}
|
|
|
|
$this->uuids[] = $hash;
|
|
|
|
return $hash;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns the entity reference of the current context as an array of identity parts
|
|
|
|
*
|
|
|
|
* @return array An array containing the identity elements of an entity
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function entity() {
|
2008-07-30 20:34:01 +00:00
|
|
|
$assoc = ($this->association) ? $this->association : $this->model;
|
2009-10-21 21:09:16 +00:00
|
|
|
if (!empty($this->entityPath)) {
|
2009-11-26 05:17:15 +00:00
|
|
|
$path = explode('.', $this->entityPath);
|
2009-10-21 21:09:16 +00:00
|
|
|
$count = count($path);
|
|
|
|
if (
|
|
|
|
($count == 1 && !empty($this->association)) ||
|
2009-10-22 03:45:42 +00:00
|
|
|
($count == 1 && $this->model != $this->entityPath) ||
|
2010-09-26 04:46:51 +00:00
|
|
|
($count == 1 && empty($this->association) && !empty($this->field)) ||
|
2009-10-21 21:09:16 +00:00
|
|
|
($count == 2 && !empty($this->fieldSuffix)) ||
|
2010-06-29 01:38:17 +00:00
|
|
|
is_numeric($path[0]) && !empty($assoc)
|
2009-10-21 21:09:16 +00:00
|
|
|
) {
|
2010-06-29 01:38:17 +00:00
|
|
|
array_unshift($path, $assoc);
|
2009-10-21 21:09:16 +00:00
|
|
|
}
|
|
|
|
return Set::filter($path);
|
|
|
|
}
|
2008-11-09 03:20:14 +00:00
|
|
|
return array_values(Set::filter(
|
2008-11-09 03:37:24 +00:00
|
|
|
array($assoc, $this->modelId, $this->field, $this->fieldSuffix)
|
2008-11-09 03:20:14 +00:00
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Allows a template or element to set a variable that will be available in
|
|
|
|
* a layout or other element. Analagous to Controller::set.
|
|
|
|
*
|
|
|
|
* @param mixed $one A string or an array of data.
|
|
|
|
* @param mixed $two Value in case $one is a string (which then works as the key).
|
2009-09-29 01:23:40 +00:00
|
|
|
* Unused if $one is an associative array, otherwise serves as the values to $one's keys.
|
|
|
|
* @return void
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
public function set($one, $two = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = null;
|
|
|
|
if (is_array($one)) {
|
|
|
|
if (is_array($two)) {
|
|
|
|
$data = array_combine($one, $two);
|
|
|
|
} else {
|
|
|
|
$data = $one;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$data = array($one => $two);
|
|
|
|
}
|
|
|
|
if ($data == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-09-18 04:13:03 +00:00
|
|
|
$this->viewVars = $data + $this->viewVars;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-03 03:50:41 +00:00
|
|
|
/**
|
2010-09-11 03:55:42 +00:00
|
|
|
* Magic accessor for helpers. Provides access to attributes that were deprecated.
|
2010-07-03 03:50:41 +00:00
|
|
|
*
|
2010-09-11 03:55:42 +00:00
|
|
|
* @param string $name Name of the attribute to get.
|
|
|
|
* @return mixed
|
2010-07-03 03:50:41 +00:00
|
|
|
*/
|
|
|
|
public function __get($name) {
|
|
|
|
if (isset($this->Helpers->{$name})) {
|
|
|
|
return $this->Helpers->{$name};
|
|
|
|
}
|
2010-09-11 03:38:15 +00:00
|
|
|
switch ($name) {
|
2010-09-11 03:55:42 +00:00
|
|
|
case 'base':
|
|
|
|
case 'here':
|
|
|
|
case 'webroot':
|
|
|
|
case 'data':
|
|
|
|
return $this->request->{$name};
|
2010-09-11 03:38:15 +00:00
|
|
|
case 'action':
|
2010-09-11 03:55:42 +00:00
|
|
|
return isset($this->request->params['action']) ? $this->request->params['action'] : '';
|
|
|
|
case 'params':
|
|
|
|
return $this->request;
|
2010-09-11 03:38:15 +00:00
|
|
|
}
|
2010-07-03 03:50:41 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interact with the HelperCollection to load all the helpers.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function loadHelpers() {
|
2010-07-04 20:57:27 +00:00
|
|
|
$helpers = HelperCollection::normalizeObjectArray($this->helpers);
|
|
|
|
foreach ($helpers as $name => $properties) {
|
|
|
|
$this->Helpers->load($properties['class'], $properties['settings'], true);
|
2010-07-03 03:50:41 +00:00
|
|
|
}
|
2010-11-05 02:29:41 +00:00
|
|
|
$this->_helpersLoaded = true;
|
2010-07-03 03:50:41 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2010-01-25 23:14:16 +00:00
|
|
|
* @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.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Rendered output
|
|
|
|
*/
|
2010-11-01 03:15:34 +00:00
|
|
|
protected function _render($___viewFn, $___dataForView = array(), $loadHelpers = true, $cached = false) {
|
|
|
|
if (empty($___dataForView)) {
|
|
|
|
$___dataForView = $this->viewVars;
|
|
|
|
}
|
2008-06-15 19:48:15 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
extract($___dataForView, EXTR_SKIP);
|
|
|
|
ob_start();
|
|
|
|
|
2010-10-27 03:12:24 +00:00
|
|
|
include $___viewFn;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2010-11-06 04:07:51 +00:00
|
|
|
return ob_get_clean();
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-07-02 02:47:20 +00:00
|
|
|
/**
|
2010-11-07 03:48:27 +00:00
|
|
|
* Loads a helper. Delegates to the `HelperCollection::load()` to load the helper
|
2010-07-02 02:47:20 +00:00
|
|
|
*
|
|
|
|
* @param string $helperName Name of the helper to load.
|
|
|
|
* @param array $settings Settings for the helper
|
|
|
|
* @return Helper a constructed helper object.
|
2010-11-07 03:48:27 +00:00
|
|
|
* @see HelperCollection::load()
|
2010-07-02 02:47:20 +00:00
|
|
|
*/
|
2010-11-07 03:48:27 +00:00
|
|
|
public function loadHelper($helperName, $settings = array()) {
|
|
|
|
return $this->Helpers->load($helperName, $settings);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Returns filename of given action's template file (.ctp) as a string.
|
|
|
|
* CamelCased action names will be under_scored! This means that you can have
|
|
|
|
* LongActionNames that refer to long_action_names.ctp views.
|
|
|
|
*
|
2010-01-25 23:14:16 +00:00
|
|
|
* @param string $name Controller action to find template filename for
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Template filename
|
2010-07-03 05:00:09 +00:00
|
|
|
* @throws MissingViewException when a view file could not be found.
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _getViewFileName($name = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$subDir = null;
|
|
|
|
|
|
|
|
if (!is_null($this->subDir)) {
|
|
|
|
$subDir = $this->subDir . DS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($name === null) {
|
|
|
|
$name = $this->action;
|
|
|
|
}
|
|
|
|
$name = str_replace('/', DS, $name);
|
|
|
|
|
2008-06-08 15:44:46 +00:00
|
|
|
if (strpos($name, DS) === false && $name[0] !== '.') {
|
2008-05-30 11:40:08 +00:00
|
|
|
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
|
|
|
|
} elseif (strpos($name, DS) !== false) {
|
|
|
|
if ($name{0} === DS || $name{1} === ':') {
|
|
|
|
if (is_file($name)) {
|
|
|
|
return $name;
|
|
|
|
}
|
|
|
|
$name = trim($name, DS);
|
2008-06-08 15:44:46 +00:00
|
|
|
} else if ($name[0] === '.') {
|
|
|
|
$name = substr($name, 3);
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
|
|
|
$name = $this->viewPath . DS . $subDir . $name;
|
|
|
|
}
|
|
|
|
}
|
2010-11-14 02:08:26 +00:00
|
|
|
$paths = $this->_paths($this->plugin);
|
2009-08-30 23:13:54 +00:00
|
|
|
|
|
|
|
$exts = array($this->ext);
|
|
|
|
if ($this->ext !== '.ctp') {
|
|
|
|
array_push($exts, '.ctp');
|
|
|
|
}
|
|
|
|
foreach ($exts as $ext) {
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
if (file_exists($path . $name . $ext)) {
|
|
|
|
return $path . $name . $ext;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$defaultPath = $paths[0];
|
|
|
|
|
|
|
|
if ($this->plugin) {
|
2009-06-07 22:24:10 +00:00
|
|
|
$pluginPaths = App::path('plugins');
|
2008-05-30 11:40:08 +00:00
|
|
|
foreach ($paths as $path) {
|
|
|
|
if (strpos($path, $pluginPaths[0]) === 0) {
|
|
|
|
$defaultPath = $path;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-30 01:37:25 +00:00
|
|
|
throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns layout filename for this template as a string.
|
|
|
|
*
|
2010-01-25 23:14:16 +00:00
|
|
|
* @param string $name The name of the layout to find.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return string Filename for layout file (.ctp).
|
2010-07-03 05:00:09 +00:00
|
|
|
* @throws MissingLayoutException when a layout cannot be located
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _getLayoutFileName($name = null) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($name === null) {
|
|
|
|
$name = $this->layout;
|
|
|
|
}
|
|
|
|
$subDir = null;
|
|
|
|
|
|
|
|
if (!is_null($this->layoutPath)) {
|
|
|
|
$subDir = $this->layoutPath . DS;
|
|
|
|
}
|
2010-11-14 02:08:26 +00:00
|
|
|
$paths = $this->_paths($this->plugin);
|
2008-05-30 11:40:08 +00:00
|
|
|
$file = 'layouts' . DS . $subDir . $name;
|
2009-08-30 23:13:54 +00:00
|
|
|
|
|
|
|
$exts = array($this->ext);
|
|
|
|
if ($this->ext !== '.ctp') {
|
|
|
|
array_push($exts, '.ctp');
|
|
|
|
}
|
|
|
|
foreach ($exts as $ext) {
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
if (file_exists($path . $file . $ext)) {
|
|
|
|
return $path . $file . $ext;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-08-30 01:37:25 +00:00
|
|
|
throw new MissingLayoutException(array('file' => $paths[0] . $file . $this->ext));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-11-10 03:16:45 +00:00
|
|
|
/**
|
|
|
|
* Finds an element filename, returns false on failure.
|
|
|
|
*
|
|
|
|
* @param string $name The name of the element to find.
|
|
|
|
* @param string $plugin The plugin name the element is in.
|
|
|
|
* @return mixed Either a string to the element filename or false when one can't be found.
|
|
|
|
*/
|
|
|
|
protected function _getElementFileName($name, $plugin = null) {
|
|
|
|
$paths = $this->_paths($plugin);
|
|
|
|
foreach ($paths as $path) {
|
|
|
|
if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
|
|
|
|
return $path . 'elements' . DS . $name . $this->ext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Return all possible paths to find view files in order
|
|
|
|
*
|
2010-01-25 23:14:16 +00:00
|
|
|
* @param string $plugin Optional plugin name to scan for view files.
|
|
|
|
* @param boolean $cached Set to true to force a refresh of view paths.
|
2008-05-30 11:40:08 +00:00
|
|
|
* @return array paths
|
|
|
|
*/
|
2010-04-05 03:21:28 +00:00
|
|
|
protected function _paths($plugin = null, $cached = true) {
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($plugin === null && $cached === true && !empty($this->__paths)) {
|
|
|
|
return $this->__paths;
|
|
|
|
}
|
|
|
|
$paths = array();
|
2010-12-05 15:24:42 +00:00
|
|
|
$viewPaths = App::path('View');
|
2009-08-24 02:43:51 +00:00
|
|
|
$corePaths = array_flip(App::core('views'));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2009-07-21 01:33:12 +00:00
|
|
|
if (!empty($plugin)) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$count = count($viewPaths);
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
2009-08-24 02:43:51 +00:00
|
|
|
if (!isset($corePaths[$viewPaths[$i]])) {
|
2009-11-26 04:58:02 +00:00
|
|
|
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
|
2009-08-24 02:43:51 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-10-14 13:28:06 +00:00
|
|
|
$paths[] = App::pluginPath($plugin) . 'views' . DS;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-11-26 05:17:15 +00:00
|
|
|
$this->__paths = array_merge($paths, $viewPaths);
|
|
|
|
return $this->__paths;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|