mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
refactoring view classes, added ScaffoldView that extends ThemeView in scaffold.php, adding tests, adding test_app with files
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6155 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
26247895aa
commit
67bbb0e93e
33 changed files with 1135 additions and 758 deletions
|
@ -171,29 +171,25 @@ class Configure extends Object {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$objects = array();
|
||||||
|
|
||||||
if (empty($path)) {
|
if (empty($path)) {
|
||||||
$pathVar = $type . 'Paths';
|
$pathVar = $type . 'Paths';
|
||||||
$path = $_this->{$pathVar};
|
$path = $_this->{$pathVar};
|
||||||
}
|
}
|
||||||
$objects = array();
|
|
||||||
$search = array_merge(array(APP), $_this->corePaths($type));
|
|
||||||
|
|
||||||
foreach ($search as $delete) {
|
|
||||||
if (is_array($path) && in_array($delete, $path)) {
|
|
||||||
$remove = array_flip($path);
|
|
||||||
unset($remove[$delete]);
|
|
||||||
$path = array_flip($remove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
$items = array();
|
||||||
foreach ((array)$path as $dir) {
|
foreach ((array)$path as $dir) {
|
||||||
|
if($type === 'file' || $type === 'class' || strpos($dir, $type) !== false) {
|
||||||
$items = $_this->__list($dir, $types[$type]['suffix'], $extension);
|
$items = $_this->__list($dir, $types[$type]['suffix'], $extension);
|
||||||
$objects = array_merge($items, $objects);
|
$objects = array_merge($items, array_diff($objects, $items));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type !== 'file') {
|
if ($type !== 'file') {
|
||||||
$objects = array_map(array(&$Inflector, 'camelize'), $objects);
|
$objects = array_map(array(&$Inflector, 'camelize'), $objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
$_this->__objects[$name] = $objects;
|
$_this->__objects[$name] = $objects;
|
||||||
$_this->__cache = true;
|
$_this->__cache = true;
|
||||||
}
|
}
|
||||||
|
@ -207,6 +203,7 @@ class Configure extends Object {
|
||||||
* @return array List of directories or files in directory
|
* @return array List of directories or files in directory
|
||||||
*/
|
*/
|
||||||
function __list($path, $suffix = false, $extension = false) {
|
function __list($path, $suffix = false, $extension = false) {
|
||||||
|
$_this =& Configure::getInstance();
|
||||||
if (!class_exists('folder')) {
|
if (!class_exists('folder')) {
|
||||||
uses('folder');
|
uses('folder');
|
||||||
}
|
}
|
||||||
|
@ -443,42 +440,42 @@ class Configure extends Object {
|
||||||
*/
|
*/
|
||||||
function corePaths($type = null) {
|
function corePaths($type = null) {
|
||||||
$paths = Cache::read('core_paths', '_cake_core_');
|
$paths = Cache::read('core_paths', '_cake_core_');
|
||||||
|
$paths = false;
|
||||||
if (!$paths) {
|
if (!$paths) {
|
||||||
$all = explode(PATH_SEPARATOR, ini_get('include_path'));
|
$all = explode(PATH_SEPARATOR, ini_get('include_path'));
|
||||||
$all = array_flip(array_flip((array_merge(array(CAKE_CORE_INCLUDE_PATH), $all))));
|
$all = array_flip(array_flip((array_merge(array(CAKE_CORE_INCLUDE_PATH), $all))));
|
||||||
|
$used = array();
|
||||||
foreach ($all as $path) {
|
foreach ($all as $path) {
|
||||||
$path = rtrim($path, DS);
|
$path = rtrim($path, DS);
|
||||||
|
if ($path == '.' || in_array(realpath($path), $used)) {
|
||||||
if ($path == '.') {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'model')) {
|
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'model')) {
|
||||||
$paths['model'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'model';
|
$paths['model'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'model' . DS;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'model' . DS . 'behaviors')) {
|
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'model' . DS . 'behaviors')) {
|
||||||
$paths['behavior'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'model' . DS . 'behaviors';
|
$paths['behavior'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'model' . DS . 'behaviors' . DS;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'controller')) {
|
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'controller')) {
|
||||||
$paths['controller'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'controller';
|
$paths['controller'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'controller' . DS;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'controller' . DS . 'components')) {
|
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'controller' . DS . 'components')) {
|
||||||
$paths['component'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'controller' . DS . 'components';
|
$paths['component'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'controller' . DS . 'components' . DS;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'view')) {
|
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'view')) {
|
||||||
$paths['view'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'view';
|
$paths['view'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'view' . DS;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'view' . DS . 'helpers')) {
|
if (is_dir($path . DS . 'cake' . DS . 'libs' . DS . 'view' . DS . 'helpers')) {
|
||||||
$paths['helper'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'view' . DS . 'helpers';
|
$paths['helper'][] = $path . DS . 'cake' . DS . 'libs' . DS . 'view' . DS . 'helpers' . DS;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DS . 'cake' . DS . 'libs')) {
|
if (is_dir($path . DS . 'cake' . DS . 'libs')) {
|
||||||
$paths['libs'][] = $path . DS . 'cake' . DS . 'libs';
|
$paths['libs'][] = $path . DS . 'cake' . DS . 'libs' . DS;
|
||||||
}
|
}
|
||||||
if (is_dir($path . DS . 'cake')) {
|
if (is_dir($path . DS . 'cake')) {
|
||||||
$paths['cake'][] = $path . DS . 'cake';
|
$paths['cake'][] = $path . DS . 'cake' . DS;
|
||||||
$paths['class'][] = $path . DS . 'cake';
|
$paths['class'][] = $path . DS . 'cake' . DS;
|
||||||
}
|
}
|
||||||
|
$used[] = $path;
|
||||||
}
|
}
|
||||||
Cache::write('core_paths', array_filter($paths), '_cake_core_');
|
Cache::write('core_paths', array_filter($paths), '_cake_core_');
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,6 +187,7 @@ class Scaffold extends Object {
|
||||||
$this->controller->set(compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
|
$this->controller->set(compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
|
||||||
'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'));
|
'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'));
|
||||||
|
|
||||||
|
$this->controller->view = 'scaffold';
|
||||||
$this->__scaffold($params);
|
$this->__scaffold($params);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -211,7 +212,7 @@ class Scaffold extends Object {
|
||||||
|
|
||||||
$this->controller->data = $this->ScaffoldModel->read();
|
$this->controller->data = $this->ScaffoldModel->read();
|
||||||
$this->controller->set(Inflector::variable($this->controller->modelClass), $this->controller->data);
|
$this->controller->set(Inflector::variable($this->controller->modelClass), $this->controller->data);
|
||||||
$this->controller->render($this->action, $this->layout, $this->__getViewFileName($params['action']));
|
$this->controller->render($this->action, $this->layout);
|
||||||
} elseif ($this->controller->_scaffoldError('view') === false) {
|
} elseif ($this->controller->_scaffoldError('view') === false) {
|
||||||
return $this->__scaffoldError();
|
return $this->__scaffoldError();
|
||||||
}
|
}
|
||||||
|
@ -227,7 +228,7 @@ class Scaffold extends Object {
|
||||||
if ($this->controller->_beforeScaffold('index')) {
|
if ($this->controller->_beforeScaffold('index')) {
|
||||||
$this->ScaffoldModel->recursive = 0;
|
$this->ScaffoldModel->recursive = 0;
|
||||||
$this->controller->set(Inflector::variable($this->controller->name), $this->controller->paginate());
|
$this->controller->set(Inflector::variable($this->controller->name), $this->controller->paginate());
|
||||||
$this->controller->render($this->action, $this->layout, $this->__getViewFileName($params['action']));
|
$this->controller->render($this->action, $this->layout);
|
||||||
} elseif ($this->controller->_scaffoldError('index') === false) {
|
} elseif ($this->controller->_scaffoldError('index') === false) {
|
||||||
return $this->__scaffoldError();
|
return $this->__scaffoldError();
|
||||||
}
|
}
|
||||||
|
@ -240,7 +241,7 @@ class Scaffold extends Object {
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __scaffoldForm($action = 'edit') {
|
function __scaffoldForm($action = 'edit') {
|
||||||
$this->controller->render($action, $this->layout, $this->__getViewFileName($action));
|
$this->controller->render($action, $this->layout);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Saves or updates the scaffolded model.
|
* Saves or updates the scaffolded model.
|
||||||
|
@ -443,66 +444,6 @@ class Scaffold extends Object {
|
||||||
return $this->cakeError('missingDatabase', array(array('webroot' => $this->controller->webroot)));
|
return $this->cakeError('missingDatabase', array(array('webroot' => $this->controller->webroot)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Returns scaffold view filename of given action's template file (.ctp) as a string.
|
|
||||||
*
|
|
||||||
* @param string $action Controller action to find template filename for
|
|
||||||
* @return string Template filename
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function __getViewFileName($action) {
|
|
||||||
$action = Inflector::underscore($action);
|
|
||||||
$scaffoldAction = 'scaffold.'.$action;
|
|
||||||
$paths = Configure::getInstance();
|
|
||||||
|
|
||||||
if (!is_null($this->webservices)) {
|
|
||||||
$type = strtolower($this->webservices) . DS;
|
|
||||||
} else {
|
|
||||||
$type = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($this->plugin)) {
|
|
||||||
if (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $scaffoldAction . $this->ext)) {
|
|
||||||
return APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $scaffoldAction . $this->ext;
|
|
||||||
} elseif (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $scaffoldAction . $this->ext)) {
|
|
||||||
return APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $scaffoldAction . $this->ext;
|
|
||||||
} elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $scaffoldAction . $this->ext)) {
|
|
||||||
return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $scaffoldAction . $this->ext;
|
|
||||||
} elseif (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $scaffoldAction . '.ctp')) {
|
|
||||||
return APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $scaffoldAction . '.ctp';
|
|
||||||
} elseif (file_exists(APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $scaffoldAction . '.thtml')) {
|
|
||||||
return APP . 'views' . DS . 'plugins' . DS . $this->plugin . DS . $this->subDir . $type . $scaffoldAction . '.thtml';
|
|
||||||
} elseif (file_exists(APP . 'views' . DS . 'plugins' . DS . 'scaffolds'. DS . $this->subDir . $type . $scaffoldAction . '.ctp')) {
|
|
||||||
return APP . 'views' . DS . 'plugins' . DS . 'scaffolds'. DS . $this->subDir . $type . $scaffoldAction . '.ctp';
|
|
||||||
} elseif (file_exists(APP . 'views' . DS . 'plugins' . DS . 'scaffolds'. DS . $this->subDir . $type . $scaffoldAction . '.thtml')) {
|
|
||||||
return APP . 'views' . DS . 'plugins' . DS . 'scaffolds'. DS . $this->subDir . $type . $scaffoldAction . '.thtml';
|
|
||||||
} elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $scaffoldAction . '.ctp')) {
|
|
||||||
return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $scaffoldAction . '.ctp';
|
|
||||||
} elseif (file_exists(APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $scaffoldAction . '.thtml')) {
|
|
||||||
return APP . 'plugins' . DS . $this->plugin . DS . 'views' . DS . $this->viewPath . DS . $scaffoldAction . '.thtml';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($paths->viewPaths as $path) {
|
|
||||||
if (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . $this->ext)) {
|
|
||||||
return $path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . $this->ext;
|
|
||||||
} elseif (file_exists($path . 'scaffolds' . DS . $this->subDir . $type . $scaffoldAction . $this->ext)) {
|
|
||||||
return $path . 'scaffolds' . DS . $this->subDir . $type . $scaffoldAction . $this->ext;
|
|
||||||
} elseif (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . '.ctp')) {
|
|
||||||
return $path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . '.ctp';
|
|
||||||
} elseif (file_exists($path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . '.thtml')) {
|
|
||||||
return $path . $this->viewPath . DS . $this->subDir . $type . $scaffoldAction . '.thtml';
|
|
||||||
} elseif (file_exists($path . 'scaffolds' . DS . $this->subDir . $type . $scaffoldAction . '.ctp')) {
|
|
||||||
return $path . 'scaffolds' . DS . $this->subDir . $type . $scaffoldAction . '.ctp';
|
|
||||||
} elseif (file_exists($path . 'scaffolds' . DS . $this->subDir . $type . $scaffoldAction . '.thtml')) {
|
|
||||||
return $path . 'scaffolds' . DS . $this->subDir . $type . $scaffoldAction . '.thtml';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($action === 'add') {
|
|
||||||
$action = 'edit';
|
|
||||||
}
|
|
||||||
return LIBS . 'view' . DS . 'templates' . DS . 'scaffolds' . DS . $action . '.ctp';
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Returns associations for controllers models.
|
* Returns associations for controllers models.
|
||||||
*
|
*
|
||||||
|
@ -524,4 +465,62 @@ class Scaffold extends Object {
|
||||||
return $associations;
|
return $associations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Scaffold View.
|
||||||
|
*
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.controller
|
||||||
|
*/
|
||||||
|
if (!class_exists('ThemeView')) {
|
||||||
|
App::import('View', 'Theme');
|
||||||
|
}
|
||||||
|
class ScaffoldView extends ThemeView {
|
||||||
|
/**
|
||||||
|
* Override _getViewFileName
|
||||||
|
*
|
||||||
|
* @return string action
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
function _getViewFileName($name = null) {
|
||||||
|
if ($name === null) {
|
||||||
|
$name = $this->action;
|
||||||
|
}
|
||||||
|
$name = Inflector::underscore($name);
|
||||||
|
$scaffoldAction = 'scaffold.'.$name;
|
||||||
|
|
||||||
|
if (!is_null($this->webservices)) {
|
||||||
|
$subDir = strtolower($this->webservices) . DS;
|
||||||
|
} else {
|
||||||
|
$subDir = null;
|
||||||
|
}
|
||||||
|
if (!is_null($this->subDir)) {
|
||||||
|
$subDir = strtolower($this->subDir) . DS;
|
||||||
|
} else {
|
||||||
|
$subDir = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($name === 'add') {
|
||||||
|
$name = 'edit';
|
||||||
|
}
|
||||||
|
|
||||||
|
$names[] = $this->viewPath . DS . $subDir . $scaffoldAction;
|
||||||
|
$names[] = 'scaffolds' . DS . $subDir . $name;
|
||||||
|
|
||||||
|
$paths = $this->_paths($this->plugin);
|
||||||
|
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
foreach ($names as $name) {
|
||||||
|
if (file_exists($path . $name . $this->ext)) {
|
||||||
|
return $path . $name . $this->ext;
|
||||||
|
} elseif (file_exists($path . $name . '.ctp')) {
|
||||||
|
return $path . $name . '.thtml';
|
||||||
|
} elseif (file_exists($path . $name . '.thtml')) {
|
||||||
|
return $path . $name . '.thtml';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_missingView($paths[0] . $name . $this->ext, 'missingView');
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
|
@ -64,6 +64,7 @@ class ThemeView extends View {
|
||||||
if (is_dir(WWW_ROOT . 'themed' . DS . $this->theme)) {
|
if (is_dir(WWW_ROOT . 'themed' . DS . $this->theme)) {
|
||||||
$this->themeWeb = 'themed/'. $this->theme .'/';
|
$this->themeWeb = 'themed/'. $this->theme .'/';
|
||||||
}
|
}
|
||||||
|
/* deprecated: as of 6128 the following properties are no longer needed */
|
||||||
$this->themeElement = 'themed'. DS . $this->theme . DS .'elements'. DS;
|
$this->themeElement = 'themed'. DS . $this->theme . DS .'elements'. DS;
|
||||||
$this->themeLayout = 'themed'. DS . $this->theme . DS .'layouts'. DS;
|
$this->themeLayout = 'themed'. DS . $this->theme . DS .'layouts'. DS;
|
||||||
$this->themePath = 'themed'. DS . $this->theme . DS;
|
$this->themePath = 'themed'. DS . $this->theme . DS;
|
||||||
|
@ -71,201 +72,28 @@ class ThemeView extends View {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter description here...
|
* Return all possible paths to find view files in order
|
||||||
*
|
*
|
||||||
* @param unknown_type $code
|
* @param string $plugin
|
||||||
* @param unknown_type $name
|
* @return array paths
|
||||||
* @param unknown_type $message
|
* @access private
|
||||||
*/
|
*/
|
||||||
function error($code, $name, $message) {
|
function _paths($plugin = null, $cached = true) {
|
||||||
$file = VIEWS . $this->themeLayout.'error'.$this->ext;
|
$paths = parent::_paths($plugin, $cached);
|
||||||
if (!file_exists($file)) {
|
|
||||||
$file = LAYOUTS.'error'.$this->ext;
|
|
||||||
}
|
|
||||||
header ("HTTP/1.0 {$code} {$name}");
|
|
||||||
print ($this->_render($file, array('code' => $code,
|
|
||||||
'name' => $name,
|
|
||||||
'message' => $message)));
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* Element.
|
|
||||||
*
|
|
||||||
* @link
|
|
||||||
* @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)
|
|
||||||
* @return string Rendered output
|
|
||||||
*/
|
|
||||||
function renderElement($name, $params = array(), $loadHelpers = false) {
|
|
||||||
|
|
||||||
if (isset($params['plugin'])) {
|
if (!empty($this->theme)) {
|
||||||
$reset = array('plugin' => $this->plugin,
|
$count = count($paths);
|
||||||
'pluginPath' => $this->pluginPath,
|
for ($i = 0; $i < $count; $i++) {
|
||||||
'pluginPaths' => $this->pluginPaths);
|
$themePaths[] = $paths[$i] . 'themed'. DS . $this->theme . DS;
|
||||||
$this->plugin = $params['plugin'];
|
}
|
||||||
$this->pluginPath = 'plugins' . DS . $this->plugin . DS;
|
$paths = array_merge($themePaths, $paths);
|
||||||
$this->pluginPaths = array(
|
|
||||||
VIEWS . $this->pluginPath,
|
|
||||||
APP . $this->pluginPath . 'views' . DS,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$paths = Configure::getInstance();
|
if(empty($this->__paths)) {
|
||||||
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
$this->__paths = $paths;
|
||||||
|
|
||||||
$file = null;
|
|
||||||
foreach ($viewPaths as $path) {
|
|
||||||
if (file_exists($path . $this->themeElement . $name . $this->ext)) {
|
|
||||||
$file = $path . $this->themeElement . $name . $this->ext;
|
|
||||||
break;
|
|
||||||
} elseif (file_exists($path . $this->themeElement . $name . '.thtml')) {
|
|
||||||
$file = $path . $this->themeElement . $name . '.thtml';
|
|
||||||
break;
|
|
||||||
} elseif (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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_null($file)) {
|
return $paths;
|
||||||
$file = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . $name. '.ctp');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file) {
|
|
||||||
$params = array_merge_recursive($params, $this->loaded);
|
|
||||||
$return = $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
|
||||||
} else {
|
|
||||||
if (!is_null($this->pluginPath)) {
|
|
||||||
$file = APP . $this->pluginPath . $this->themeElement . $name . $this->ext;
|
|
||||||
} else {
|
|
||||||
$file = VIEWS . $this->themeElement . $name . $this->ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Configure::read() > 0) {
|
|
||||||
$return = 'Not Found: ' . $file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($params['plugin'])) {
|
|
||||||
$this->plugin = $reset['plugin'];
|
|
||||||
$this->pluginPath = $reset['pluginPath'];
|
|
||||||
$this->pluginPaths = $reset['pluginPaths'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @param unknown_type $action
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function _getViewFileName($action) {
|
|
||||||
$action = Inflector::underscore($action);
|
|
||||||
|
|
||||||
if (!is_null($this->webservices)) {
|
|
||||||
$type = strtolower($this->webservices) . DS;
|
|
||||||
} else {
|
|
||||||
$type = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$position = strpos($action, '..');
|
|
||||||
if ($position !== false) {
|
|
||||||
$action = explode('/', $action);
|
|
||||||
$i = array_search('..', $action);
|
|
||||||
unset($action[$i - 1]);
|
|
||||||
unset($action[$i]);
|
|
||||||
$action = '..' . DS . implode(DS, $action);
|
|
||||||
}
|
|
||||||
|
|
||||||
$paths = Configure::getInstance();
|
|
||||||
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
|
||||||
|
|
||||||
$name = $this->viewPath . DS . $this->subDir . $type . $action;
|
|
||||||
foreach ($viewPaths as $path) {
|
|
||||||
if (file_exists($path . $this->themePath . $name . $this->ext)) {
|
|
||||||
return $path . $this->themePath . $name . $this->ext;
|
|
||||||
} elseif (file_exists($path . $this->themePath . $name . '.thtml')) {
|
|
||||||
return $path . $this->themePath . $name . '.thtml';
|
|
||||||
} elseif (file_exists($path . $name . $this->ext)) {
|
|
||||||
return $path . $name . $this->ext;
|
|
||||||
} elseif (file_exists($path . $name . '.thtml')) {
|
|
||||||
return $path . $name . '.thtml';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) {
|
|
||||||
return $viewFileName;
|
|
||||||
} elseif ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) {
|
|
||||||
return $viewFileName;
|
|
||||||
} else {
|
|
||||||
if (!is_null($this->pluginPath)) {
|
|
||||||
$viewFileName = APP . $this->pluginPath . $this->themePath . $name . $this->ext;
|
|
||||||
} else {
|
|
||||||
$viewFileName = VIEWS . $this->themePath . $name . $this->ext;
|
|
||||||
}
|
|
||||||
$this->_missingView($viewFileName, $action);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter description here...
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
function _getLayoutFileName() {
|
|
||||||
if (isset($this->webservices) && !is_null($this->webservices)) {
|
|
||||||
$type = strtolower($this->webservices) . DS;
|
|
||||||
} else {
|
|
||||||
$type = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($this->layoutPath)) {
|
|
||||||
$type = $this->layoutPath . DS;
|
|
||||||
}
|
|
||||||
|
|
||||||
$paths = Configure::getInstance();
|
|
||||||
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
|
||||||
|
|
||||||
$name = $this->subDir . $type . $this->layout;
|
|
||||||
foreach ($viewPaths as $path) {
|
|
||||||
if (file_exists($path . $this->themeLayout . $name . $this->ext)) {
|
|
||||||
return $path . $this->themeLayout . $name . $this->ext;
|
|
||||||
} elseif (file_exists($path . $this->themeLayout . $name . '.thtml')) {
|
|
||||||
return $path . $this->themeLayout . $name . '.thtml';
|
|
||||||
} elseif (file_exists($path . 'layouts' . DS . $name . $this->ext)) {
|
|
||||||
return $path . 'layouts' . DS . $name . $this->ext;
|
|
||||||
} elseif (file_exists($path . 'layouts' . DS . $name . '.thtml')) {
|
|
||||||
return $path . 'layouts' . DS . $name . '.thtml';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($this->pluginPath)) {
|
|
||||||
$layoutFileName = APP . $this->pluginPath . 'views' . DS . $this->themeLayout . $name . $this->ext;
|
|
||||||
} else {
|
|
||||||
$layoutFileName = VIEWS . $this->themeLayout . $name . $this->ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . $this->layout . '.ctp');
|
|
||||||
if (empty($default) && !empty($type)) {
|
|
||||||
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . 'default.ctp');
|
|
||||||
}
|
|
||||||
if (empty($default)) {
|
|
||||||
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $this->layout . '.ctp');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($default)) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
return $layoutFileName;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -41,27 +41,32 @@ uses ('view' . DS . 'helper', 'class_registry');
|
||||||
*/
|
*/
|
||||||
class View extends Object {
|
class View extends Object {
|
||||||
/**
|
/**
|
||||||
* Name of the controller.
|
* Path parts for creating links in views.
|
||||||
*
|
*
|
||||||
* @var string Name of controller
|
* @var string Base URL
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $name = null;
|
var $base = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the current URL (for links etc.)
|
* Stores the current URL (for links etc.)
|
||||||
*
|
*
|
||||||
* @var string Current URL
|
* @var string Current URL
|
||||||
*/
|
*/
|
||||||
var $here = null;
|
var $here = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Not used. 2006-09
|
* Name of the plugin.
|
||||||
*
|
*
|
||||||
* @var unknown_type
|
* @link http://manual.cakephp.org/chapter/plugins
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $plugin = null;
|
||||||
|
/**
|
||||||
|
* Name of the controller.
|
||||||
|
*
|
||||||
|
* @var string Name of controller
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $parent = null;
|
var $name = null;
|
||||||
/**
|
/**
|
||||||
* Action to be performed.
|
* Action to be performed.
|
||||||
*
|
*
|
||||||
|
@ -69,6 +74,116 @@ class View extends Object {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $action = null;
|
var $action = null;
|
||||||
|
/**
|
||||||
|
* Array of parameter data
|
||||||
|
*
|
||||||
|
* @var array Parameter data
|
||||||
|
*/
|
||||||
|
var $params = array();
|
||||||
|
/**
|
||||||
|
* Current passed params
|
||||||
|
*
|
||||||
|
* @var mixed
|
||||||
|
*/
|
||||||
|
var $passedArgs = array();
|
||||||
|
/**
|
||||||
|
* Array of data
|
||||||
|
*
|
||||||
|
* @var array Parameter data
|
||||||
|
*/
|
||||||
|
var $data = array();
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
var $helpers = array('Html');
|
||||||
|
/**
|
||||||
|
* Path to View.
|
||||||
|
*
|
||||||
|
* @var string Path to View
|
||||||
|
*/
|
||||||
|
var $viewPath = null;
|
||||||
|
/**
|
||||||
|
* Variables for the view
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $viewVars = array();
|
||||||
|
/**
|
||||||
|
* Name of layout to use with this View.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $layout = 'default';
|
||||||
|
/**
|
||||||
|
* Path to Layout.
|
||||||
|
*
|
||||||
|
* @var string Path to Layout
|
||||||
|
*/
|
||||||
|
var $layoutPath = null;
|
||||||
|
/**
|
||||||
|
* Title HTML element of this View.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $pageTitle = false;
|
||||||
|
/**
|
||||||
|
* Turns on or off Cake's conventional mode of rendering views. On by default.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $autoRender = true;
|
||||||
|
/**
|
||||||
|
* Turns on or off Cake's conventional mode of finding layout files. On by default.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $autoLayout = true;
|
||||||
|
/**
|
||||||
|
* File extension. Defaults to Cake's template ".ctp".
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $ext = '.ctp';
|
||||||
|
/**
|
||||||
|
* Sub-directory for this view file.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $subDir = null;
|
||||||
|
/**
|
||||||
|
* Theme name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $themeWeb = null;
|
||||||
|
/**
|
||||||
|
* Used to define methods a controller that will be cached.
|
||||||
|
*
|
||||||
|
* @see Controller::$cacheAction
|
||||||
|
* @var mixed
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
var $cacheAction = false;
|
||||||
|
/**
|
||||||
|
* True when the view has been rendered.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
var $hasRendered = null;
|
||||||
|
/**
|
||||||
|
* Array of loaded view helpers.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $loaded = array();
|
||||||
/**
|
/**
|
||||||
* True if in scope of model-specific region
|
* True if in scope of model-specific region
|
||||||
*
|
*
|
||||||
|
@ -106,38 +221,18 @@ class View extends Object {
|
||||||
*/
|
*/
|
||||||
var $modelId = null;
|
var $modelId = null;
|
||||||
/**
|
/**
|
||||||
* An array of names of models the particular controller wants to use.
|
* List of generated DOM UUIDs
|
||||||
*
|
|
||||||
* @var mixed A single name as a string or a list of names as an array.
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
var $uses = false;
|
|
||||||
/**
|
|
||||||
* 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 protected
|
|
||||||
*/
|
|
||||||
var $helpers = array('Html');
|
|
||||||
/**
|
|
||||||
* Path to View.
|
|
||||||
*
|
|
||||||
* @var string Path to View
|
|
||||||
*/
|
|
||||||
var $viewPath;
|
|
||||||
/**
|
|
||||||
* Path to Layout.
|
|
||||||
*
|
|
||||||
* @var string Path to Layout
|
|
||||||
*/
|
|
||||||
var $layoutPath = null;
|
|
||||||
/**
|
|
||||||
* Variables for the view
|
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
* @access public
|
|
||||||
*/
|
*/
|
||||||
var $viewVars = array();
|
var $uuids = array();
|
||||||
|
/**
|
||||||
|
* List of variables to collect from the associated controller
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
var $__passedVars = array('viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot', 'helpers', 'here', 'layout', 'name', 'pageTitle', 'layoutPath', 'viewPath', 'params', 'data', 'webservices', 'plugin', 'passedArgs', 'cacheAction');
|
||||||
/**
|
/**
|
||||||
* Scripts (and/or other <head /> tags) for the layout
|
* Scripts (and/or other <head /> tags) for the layout
|
||||||
*
|
*
|
||||||
|
@ -146,123 +241,11 @@ class View extends Object {
|
||||||
*/
|
*/
|
||||||
var $__scripts = array();
|
var $__scripts = array();
|
||||||
/**
|
/**
|
||||||
* Title HTML element of this View.
|
* Holds an array of paths.
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $pageTitle = false;
|
|
||||||
/**
|
|
||||||
* An array of model objects.
|
|
||||||
*
|
|
||||||
* @var array Array of model objects.
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $models = array();
|
|
||||||
/**
|
|
||||||
* Path parts for creating links in views.
|
|
||||||
*
|
|
||||||
* @var string Base URL
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $base = null;
|
|
||||||
/**
|
|
||||||
* Name of layout to use with this View.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $layout = 'default';
|
|
||||||
/**
|
|
||||||
* Turns on or off Cake's conventional mode of rendering views. On by default.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $autoRender = true;
|
|
||||||
/**
|
|
||||||
* Turns on or off Cake's conventional mode of finding layout files. On by default.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
var $autoLayout = true;
|
|
||||||
/**
|
|
||||||
* Array of parameter data
|
|
||||||
*
|
|
||||||
* @var array Parameter data
|
|
||||||
*/
|
|
||||||
var $params = array();
|
|
||||||
/**
|
|
||||||
* True when the view has been rendered.
|
|
||||||
*
|
|
||||||
* @var boolean
|
|
||||||
*/
|
|
||||||
var $hasRendered = null;
|
|
||||||
/**
|
|
||||||
* Array of loaded view helpers.
|
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
var $loaded = array();
|
var $__paths = array();
|
||||||
/**
|
|
||||||
* File extension. Defaults to Cake's template ".ctp".
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $ext = '.ctp';
|
|
||||||
/**
|
|
||||||
* Sub-directory for this view file.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $subDir = null;
|
|
||||||
/**
|
|
||||||
* Theme name.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $themeWeb = null;
|
|
||||||
/**
|
|
||||||
* Plugin name. A Plugin is a sub-application.
|
|
||||||
*
|
|
||||||
* @link http://manual.cakephp.org/chapter/plugins
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $plugin = null;
|
|
||||||
/**
|
|
||||||
* Creates system path to plugin: plugins . DS . plugin_name . DS
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
var $pluginPath = null;
|
|
||||||
/**
|
|
||||||
* Holds an array of plugin paths.
|
|
||||||
* VIEWS . $this->pluginPath
|
|
||||||
* APP . $this->pluginPath . views . DS
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
var $pluginPaths = array();
|
|
||||||
/**
|
|
||||||
* Current passed params
|
|
||||||
*
|
|
||||||
* @var mixed
|
|
||||||
*/
|
|
||||||
var $passedArgs = array();
|
|
||||||
/**
|
|
||||||
* List of variables to collect from the associated controller
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
* @access protected
|
|
||||||
*/
|
|
||||||
var $__passedVars = array('viewVars', 'action', 'autoLayout', 'autoRender', 'ext', 'base', 'webroot', 'helpers', 'here', 'layout', 'modelNames', 'name', 'pageTitle', 'layoutPath', 'viewPath', 'params', 'data', 'webservices', 'plugin', 'passedArgs', 'cacheAction');
|
|
||||||
/**
|
|
||||||
* List of generated DOM UUIDs
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
var $uuids = array();
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
@ -276,134 +259,13 @@ class View extends Object {
|
||||||
$this->{$var} = $controller->{$var};
|
$this->{$var} = $controller->{$var};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!is_null($this->plugin)) {
|
|
||||||
$this->pluginPath = 'plugins'. DS . $this->plugin . DS;
|
|
||||||
$this->pluginPaths = array(
|
|
||||||
VIEWS . $this->pluginPath,
|
|
||||||
APP . $this->pluginPath . 'views' . DS,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
if($register) {
|
if($register) {
|
||||||
ClassRegistry::addObject('view', $this);
|
ClassRegistry::addObject('view', $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
function render($action = null, $layout = null, $file = null) {
|
|
||||||
|
|
||||||
if (isset($this->hasRendered) && $this->hasRendered) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
$this->hasRendered = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$action) {
|
|
||||||
$action = $this->action;
|
|
||||||
}
|
|
||||||
$tempLayout = $this->layout;
|
|
||||||
|
|
||||||
if ($layout) {
|
|
||||||
$this->layout = $layout;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file) {
|
|
||||||
$viewFileName = $file;
|
|
||||||
$this->_missingView($viewFileName, $action);
|
|
||||||
} else {
|
|
||||||
$viewFileName = $this->_getViewFileName($action);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($viewFileName && !$this->hasRendered) {
|
|
||||||
if (substr($viewFileName, -3) === 'ctp' || substr($viewFileName, -5) === 'thtml') {
|
|
||||||
$out = View::_render($viewFileName, $this->viewVars);
|
|
||||||
} else {
|
|
||||||
$out = $this->_render($viewFileName, $this->viewVars);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($out !== false) {
|
|
||||||
if ($this->layout && $this->autoLayout) {
|
|
||||||
$out = $this->renderLayout($out);
|
|
||||||
if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) {
|
|
||||||
$replace = array('<cake:nocache>', '</cake:nocache>');
|
|
||||||
$out = str_replace($replace, '', $out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
print $out;
|
|
||||||
$this->layout = $tempLayout;
|
|
||||||
$this->hasRendered = true;
|
|
||||||
} else {
|
|
||||||
$out = $this->_render($viewFileName, $this->viewVars);
|
|
||||||
trigger_error(sprintf(__("Error in view %s, got: <blockquote>%s</blockquote>", true), $viewFileName, $out), E_USER_ERROR);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* Element.
|
|
||||||
*
|
|
||||||
* @link
|
|
||||||
* @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)
|
|
||||||
* @return string Rendered output
|
|
||||||
*/
|
|
||||||
function renderElement($name, $params = array(), $loadHelpers = false) {
|
|
||||||
|
|
||||||
if (isset($params['plugin'])) {
|
|
||||||
$this->plugin = $params['plugin'];
|
|
||||||
$this->pluginPath = 'plugins' . DS . $this->plugin . DS;
|
|
||||||
$this->pluginPaths = array(
|
|
||||||
VIEWS . $this->pluginPath,
|
|
||||||
APP . $this->pluginPath . 'views' . DS,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$paths = Configure::getInstance();
|
|
||||||
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
|
||||||
|
|
||||||
$file = null;
|
|
||||||
foreach ($viewPaths 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_null($file)) {
|
|
||||||
$file = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . $name. '.ctp');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($file) {
|
|
||||||
$params = array_merge_recursive($params, $this->loaded);
|
|
||||||
return $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($this->pluginPath)) {
|
|
||||||
$file = APP . $this->pluginPath . 'views' . DS . 'elements' . DS . $name . $this->ext;
|
|
||||||
} else {
|
|
||||||
$file = VIEWS . 'elements' . DS . $name . $this->ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Configure::read() > 0) {
|
|
||||||
return "Not Found: " . $file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for View::renderElement();
|
* Wrapper for View::renderElement();
|
||||||
*
|
*
|
||||||
|
@ -442,20 +304,113 @@ class View extends Object {
|
||||||
}
|
}
|
||||||
return $this->renderElement($name, $params);
|
return $this->renderElement($name, $params);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
function render($action = null, $layout = null, $file = null) {
|
||||||
|
|
||||||
|
if (isset($this->hasRendered) && $this->hasRendered) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
$this->hasRendered = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$action) {
|
||||||
|
$action = $this->action;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($layout === null) {
|
||||||
|
$layout = $this->layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($file != null) {
|
||||||
|
$action = $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
$viewFileName = $this->_getViewFileName($action);
|
||||||
|
|
||||||
|
if ($viewFileName && !$this->hasRendered) {
|
||||||
|
if (substr($viewFileName, -3) === 'ctp' || substr($viewFileName, -5) === 'thtml') {
|
||||||
|
$out = View::_render($viewFileName, $this->viewVars);
|
||||||
|
} else {
|
||||||
|
$out = $this->_render($viewFileName, $this->viewVars);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($out !== false) {
|
||||||
|
if ($this->layout && $this->autoLayout) {
|
||||||
|
$out = $this->renderLayout($out, $layout);
|
||||||
|
if (isset($this->loaded['cache']) && (($this->cacheAction != false)) && (Configure::read('Cache.check') === true)) {
|
||||||
|
$replace = array('<cake:nocache>', '</cake:nocache>');
|
||||||
|
$out = str_replace($replace, '', $out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print $out;
|
||||||
|
$this->hasRendered = true;
|
||||||
|
} else {
|
||||||
|
$out = $this->_render($viewFileName, $this->viewVars);
|
||||||
|
trigger_error(sprintf(__("Error in view %s, got: <blockquote>%s</blockquote>", true), $viewFileName, $out), E_USER_ERROR);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
* Element.
|
||||||
|
*
|
||||||
|
* @link
|
||||||
|
* @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)
|
||||||
|
* @return string Rendered output
|
||||||
|
*/
|
||||||
|
function renderElement($name, $params = array(), $loadHelpers = false) {
|
||||||
|
$file = $plugin = false;
|
||||||
|
if (isset($params['plugin'])) {
|
||||||
|
$plugin = $params['plugin'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_file($file)) {
|
||||||
|
$params = array_merge_recursive($params, $this->loaded);
|
||||||
|
return $this->_render($file, array_merge($this->viewVars, $params), $loadHelpers);
|
||||||
|
}
|
||||||
|
|
||||||
|
$file = $paths[0] . 'views' . DS . 'elements' . DS . $name . $this->ext;
|
||||||
|
if (Configure::read() > 0) {
|
||||||
|
return "Not Found: " . $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Renders a layout. Returns output from _render(). Returns false on error.
|
* Renders a layout. Returns output from _render(). Returns false on error.
|
||||||
*
|
*
|
||||||
* @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
|
* @param string $content_for_layout Content to render in a view, wrapped by the surrounding layout.
|
||||||
* @return mixed Rendered output, or false on error
|
* @return mixed Rendered output, or false on error
|
||||||
*/
|
*/
|
||||||
function renderLayout($content_for_layout) {
|
function renderLayout($content_for_layout, $layout = null) {
|
||||||
$layout_fn = $this->_getLayoutFileName();
|
$layout_fn = $this->_getLayoutFileName($layout);
|
||||||
|
|
||||||
|
$debug = '';
|
||||||
if (Configure::read() > 2 && isset($this->viewVars['cakeDebug'])) {
|
if (Configure::read() > 2 && isset($this->viewVars['cakeDebug'])) {
|
||||||
$debug = View::_render(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . 'dump.ctp', array('controller' => $this->viewVars['cakeDebug']), false);
|
$debug = View::_render(LIBS . 'view' . DS . 'templates' . DS . 'elements' . DS . 'dump.ctp', array('controller' => $this->viewVars['cakeDebug']), false);
|
||||||
unset($this->viewVars['cakeDebug']);
|
unset($this->viewVars['cakeDebug']);
|
||||||
} else {
|
|
||||||
$debug = '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->pageTitle !== false) {
|
if ($this->pageTitle !== false) {
|
||||||
|
@ -473,7 +428,6 @@ class View extends Object {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (is_file($layout_fn)) {
|
|
||||||
if (empty($this->loaded) && !empty($this->helpers)) {
|
if (empty($this->loaded) && !empty($this->helpers)) {
|
||||||
$loadHelpers = true;
|
$loadHelpers = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -491,17 +445,39 @@ class View extends Object {
|
||||||
$out = $this->_render($layout_fn, $data_for_layout);
|
$out = $this->_render($layout_fn, $data_for_layout);
|
||||||
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>", true), $layout_fn, $out), E_USER_ERROR);
|
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>", true), $layout_fn, $out), E_USER_ERROR);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Render cached view
|
||||||
|
*
|
||||||
|
* @param string $filename the cache file to include
|
||||||
|
* @param string $timeStart the page render start time
|
||||||
|
*/
|
||||||
|
function renderCache($filename, $timeStart) {
|
||||||
|
ob_start();
|
||||||
|
include ($filename);
|
||||||
|
|
||||||
|
if (Configure::read() > 0 && $this->layout != 'xml') {
|
||||||
|
echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->";
|
||||||
|
}
|
||||||
|
|
||||||
|
$out = ob_get_clean();
|
||||||
|
|
||||||
|
if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match)) {
|
||||||
|
if (time() >= $match['1']) {
|
||||||
|
@unlink($filename);
|
||||||
|
unset ($out);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
return $this->cakeError('missingLayout', array(
|
if ($this->layout === 'xml') {
|
||||||
array(
|
header('Content-type: text/xml');
|
||||||
'layout' => $this->layout,
|
}
|
||||||
'file' => $layout_fn,
|
$out = str_replace('<!--cachetime:'.$match['1'].'-->', '', $out);
|
||||||
'base' => $this->base
|
e($out);
|
||||||
)
|
die();
|
||||||
));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -582,7 +558,6 @@ class View extends Object {
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
function set($one, $two = null) {
|
function set($one, $two = null) {
|
||||||
|
|
||||||
$data = null;
|
$data = null;
|
||||||
if (is_array($one)) {
|
if (is_array($one)) {
|
||||||
if (is_array($two)) {
|
if (is_array($two)) {
|
||||||
|
@ -617,7 +592,7 @@ class View extends Object {
|
||||||
function error($code, $name, $message) {
|
function error($code, $name, $message) {
|
||||||
header ("HTTP/1.1 {$code} {$name}");
|
header ("HTTP/1.1 {$code} {$name}");
|
||||||
print ($this->_render(
|
print ($this->_render(
|
||||||
LAYOUTS . 'error.ctp',
|
$this->_getLayoutFileName('error'),
|
||||||
array(
|
array(
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
|
@ -626,111 +601,6 @@ class View extends Object {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Private methods.
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* @param string $action Controller action to find template filename for
|
|
||||||
* @return string Template filename
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function _getViewFileName($action) {
|
|
||||||
$action = Inflector::underscore($action);
|
|
||||||
|
|
||||||
if (!is_null($this->webservices)) {
|
|
||||||
$type = strtolower($this->webservices) . DS;
|
|
||||||
} else {
|
|
||||||
$type = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$position = strpos($action, '..');
|
|
||||||
if ($position !== false) {
|
|
||||||
$action = explode('/', $action);
|
|
||||||
$i = array_search('..', $action);
|
|
||||||
unset($action[$i - 1]);
|
|
||||||
unset($action[$i]);
|
|
||||||
$action = '..' . DS . implode(DS, $action);
|
|
||||||
}
|
|
||||||
|
|
||||||
$paths = Configure::getInstance();
|
|
||||||
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
|
||||||
|
|
||||||
$name = $this->viewPath . DS . $this->subDir . $type . $action;
|
|
||||||
foreach ($viewPaths as $path) {
|
|
||||||
if (file_exists($path . $name . $this->ext)) {
|
|
||||||
return $path . $name . $this->ext;
|
|
||||||
} elseif (file_exists($path . $name . '.thtml')) {
|
|
||||||
return $path . $name . '.thtml';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'errors' . DS . $type . $action . '.ctp')) {
|
|
||||||
return $viewFileName;
|
|
||||||
} elseif ($viewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $this->viewPath . DS . $type . $action . '.ctp')) {
|
|
||||||
return $viewFileName;
|
|
||||||
} else {
|
|
||||||
if (!is_null($this->pluginPath)) {
|
|
||||||
$viewFileName = APP . $this->pluginPath . 'views' . DS . $name . $this->ext;
|
|
||||||
} else {
|
|
||||||
$viewFileName = VIEWS . $name . $this->ext;
|
|
||||||
}
|
|
||||||
$this->_missingView($viewFileName, $action);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns layout filename for this template as a string.
|
|
||||||
*
|
|
||||||
* @return string Filename for layout file (.ctp).
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function _getLayoutFileName() {
|
|
||||||
if (isset($this->webservices) && !is_null($this->webservices)) {
|
|
||||||
$type = strtolower($this->webservices) . DS;
|
|
||||||
} else {
|
|
||||||
$type = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($this->layoutPath)) {
|
|
||||||
$type = $this->layoutPath . DS;
|
|
||||||
}
|
|
||||||
|
|
||||||
$paths = Configure::getInstance();
|
|
||||||
$viewPaths = array_merge($this->pluginPaths, $paths->viewPaths);
|
|
||||||
|
|
||||||
$name = $this->subDir . $type . $this->layout;
|
|
||||||
foreach ($viewPaths as $path) {
|
|
||||||
if (file_exists($path . 'layouts' . DS . $name . $this->ext)) {
|
|
||||||
return $path . 'layouts' . DS . $name . $this->ext;
|
|
||||||
} elseif (file_exists($path . 'layouts' . DS . $name . '.thtml')) {
|
|
||||||
return $path . 'layouts' . DS . $name . '.thtml';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($this->pluginPath)) {
|
|
||||||
$layoutFileName = APP . $this->pluginPath . 'views' . DS . 'layouts' . DS . $name . $this->ext;
|
|
||||||
} else {
|
|
||||||
$layoutFileName = VIEWS . 'layouts' . DS . $name . $this->ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . $this->layout . '.ctp');
|
|
||||||
if (empty($default) && !empty($type)) {
|
|
||||||
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $type . 'default.ctp');
|
|
||||||
}
|
|
||||||
if (empty($default)) {
|
|
||||||
$default = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . 'layouts' . DS . $this->layout . '.ctp');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($default)) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
return $layoutFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders and returns output for given view filename with its
|
* Renders and returns output for given view filename with its
|
||||||
* array of data.
|
* array of data.
|
||||||
|
@ -738,7 +608,7 @@ class View extends Object {
|
||||||
* @param string $___viewFn Filename of the view
|
* @param string $___viewFn Filename of the view
|
||||||
* @param array $___dataForView Data to include in rendered view
|
* @param array $___dataForView Data to include in rendered view
|
||||||
* @return string Rendered output
|
* @return string Rendered output
|
||||||
* @access private
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) {
|
function _render($___viewFn, $___dataForView, $loadHelpers = true, $cached = false) {
|
||||||
if ($this->helpers != false && $loadHelpers === true) {
|
if ($this->helpers != false && $loadHelpers === true) {
|
||||||
|
@ -882,35 +752,90 @@ class View extends Object {
|
||||||
return $loaded;
|
return $loaded;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Render cached view
|
* 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.
|
||||||
*
|
*
|
||||||
* @param string $filename the cache file to include
|
* @param string $action Controller action to find template filename for
|
||||||
* @param string $timeStart the page render start time
|
* @return string Template filename
|
||||||
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function renderCache($filename, $timeStart) {
|
function _getViewFileName($name = null) {
|
||||||
ob_start();
|
$subDir = null;
|
||||||
include ($filename);
|
if (!is_null($this->webservices)) {
|
||||||
|
$subDir = strtolower($this->webservices) . DS;
|
||||||
if (Configure::read() > 0 && $this->layout != 'xml') {
|
}
|
||||||
echo "<!-- Cached Render Time: " . round(getMicrotime() - $timeStart, 4) . "s -->";
|
if (!is_null($this->subDir)) {
|
||||||
|
$subDir = $this->subDir . DS;
|
||||||
}
|
}
|
||||||
|
|
||||||
$out = ob_get_clean();
|
if($name === null) {
|
||||||
|
$name = $this->action;
|
||||||
|
}
|
||||||
|
|
||||||
if (preg_match('/^<!--cachetime:(\\d+)-->/', $out, $match)) {
|
if(strpos($name, '/') === false && strpos($name, '..') === false) {
|
||||||
if (time() >= $match['1']) {
|
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
|
||||||
@unlink($filename);
|
} elseif (strpos($name, '/') !== false) {
|
||||||
unset ($out);
|
if($name{0} === '/') {
|
||||||
return;
|
if (is_file($name)) {
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
$name = trim($name, '/');
|
||||||
|
if(DS !== '/') {
|
||||||
|
$name = implode(DS, explode('/', $name));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if ($this->layout === 'xml') {
|
if (is_file($name)) {
|
||||||
header('Content-type: text/xml');
|
return $name;
|
||||||
}
|
}
|
||||||
$out = str_replace('<!--cachetime:'.$match['1'].'-->', '', $out);
|
return $this->_missingView($name, 'missingView');
|
||||||
e($out);
|
}
|
||||||
die();
|
} elseif (strpos($name, '..') !== false) {
|
||||||
|
$name = explode('/', $name);
|
||||||
|
$i = array_search('..', $name);
|
||||||
|
unset($name[$i - 1]);
|
||||||
|
unset($name[$i]);
|
||||||
|
$name = '..' . DS . implode(DS, $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
$paths = $this->_paths($this->plugin);
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
if (file_exists($path . $name . $this->ext)) {
|
||||||
|
return $path . $name . $this->ext;
|
||||||
|
} elseif (file_exists($path . $name . '.thtml')) {
|
||||||
|
return $path . $name . '.thtml';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->_missingView($paths[0] . $name . $this->ext, 'missingView');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns layout filename for this template as a string.
|
||||||
|
*
|
||||||
|
* @return string Filename for layout file (.ctp).
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
function _getLayoutFileName($name = null) {
|
||||||
|
if($name === null) {
|
||||||
|
$name = $this->layout;
|
||||||
|
}
|
||||||
|
$subDir = null;
|
||||||
|
if (!is_null($this->layoutPath)) {
|
||||||
|
$subDir = $this->layoutPath . DS;
|
||||||
|
}
|
||||||
|
|
||||||
|
$paths = $this->_paths($this->plugin);
|
||||||
|
$file = 'layouts' . DS . $subDir . $name;
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
if (file_exists($path . $file . $this->ext)) {
|
||||||
|
return $path . $file . $this->ext;
|
||||||
|
} elseif (file_exists($path . $file . '.thtml')) {
|
||||||
|
return $path . $file . '.thtml';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout');
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Return a misssing view error message
|
* Return a misssing view error message
|
||||||
|
@ -918,42 +843,69 @@ class View extends Object {
|
||||||
* @param string $viewFileName the filename that should exist
|
* @param string $viewFileName the filename that should exist
|
||||||
* @return cakeError
|
* @return cakeError
|
||||||
*/
|
*/
|
||||||
function _missingView($viewFileName = null, $action = null) {
|
function _missingView($file, $error = 'missingView') {
|
||||||
if (!is_file($viewFileName) && !fileExistsInPath($viewFileName) || $viewFileName === '/' || $viewFileName === '\\') {
|
$paths = $this->_paths($this->plugin);
|
||||||
if (strpos($action, 'missingAction') !== false) {
|
$name = 'errors' . DS . Inflector::underscore($error);
|
||||||
$errorAction = 'missingAction';
|
foreach ($paths as $path) {
|
||||||
} else {
|
if (file_exists($path . $name . $this->ext)) {
|
||||||
$errorAction = 'missingView';
|
$name = $path . $name . $this->ext;
|
||||||
}
|
break;
|
||||||
|
} elseif (file_exists($path . $name . '.thtml')) {
|
||||||
foreach (array($this->name, 'errors') as $viewDir) {
|
$name = $path . $name . '.thtml';
|
||||||
$errorAction = Inflector::underscore($errorAction);
|
|
||||||
if (file_exists(VIEWS . $viewDir . DS . $errorAction . $this->ext)) {
|
|
||||||
$missingViewFileName = VIEWS . $viewDir . DS . $errorAction . $this->ext;
|
|
||||||
} elseif (file_exists(VIEWS . $viewDir . DS . $errorAction . '.thtml')) {
|
|
||||||
$missingViewFileName = VIEWS . $viewDir . DS . $errorAction . '.thtml';
|
|
||||||
} elseif ($missingViewFileName = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . $viewDir . DS . $errorAction . '.ctp')) {
|
|
||||||
} else {
|
|
||||||
$missingViewFileName = false;
|
|
||||||
}
|
|
||||||
$missingViewExists = is_file($missingViewFileName);
|
|
||||||
|
|
||||||
if ($missingViewExists) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($action, 'missingView') === false) {
|
if ($error === 'missingView') {
|
||||||
return $this->cakeError('missingView', array(array(
|
return $this->cakeError('missingView', array(array(
|
||||||
'className' => $this->name,
|
'className' => $this->name,
|
||||||
'action' => $this->action,
|
'action' => $this->action,
|
||||||
'file' => $viewFileName,
|
'file' => $file,
|
||||||
'base' => $this->base
|
'base' => $this->base
|
||||||
)));
|
)));
|
||||||
exit();
|
|
||||||
}
|
}
|
||||||
|
if ($error === 'missingLayout') {
|
||||||
|
return $this->cakeError('missingLayout', array(array(
|
||||||
|
'layout' => $this->layout,
|
||||||
|
'file' => $file,
|
||||||
|
'base' => $this->base
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Return all possible paths to find view files in order
|
||||||
|
*
|
||||||
|
* @param string $plugin
|
||||||
|
* @return array paths
|
||||||
|
* @access protected
|
||||||
|
*/
|
||||||
|
function _paths($plugin = null, $cached = true) {
|
||||||
|
if($plugin === null && $cached === true && !empty($this->__paths)) {
|
||||||
|
return $this->__paths;
|
||||||
|
}
|
||||||
|
$paths = array();
|
||||||
|
$viewPaths = Configure::read('viewPaths');
|
||||||
|
if ($plugin !== null) {
|
||||||
|
$count = count($viewPaths);
|
||||||
|
for ($i = 0; $i < $count; $i++) {
|
||||||
|
$paths[] = $viewPaths[$i] . 'plugins' . DS . $plugin . DS;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginPaths = Configure::read('pluginPaths');
|
||||||
|
$count = count($pluginPaths);
|
||||||
|
for ($i = 0; $i < $count; $i++) {
|
||||||
|
$paths[] = $pluginPaths[$i] . $plugin . DS . 'views' . DS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$paths = array_merge($paths, $viewPaths);
|
||||||
|
|
||||||
|
if(empty($this->__paths)) {
|
||||||
|
$this->__paths = $paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $paths;
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
|
@ -44,6 +44,24 @@ class ConfigureTest extends UnitTestCase {
|
||||||
$this->assertTrue(in_array('Xml', $result));
|
$this->assertTrue(in_array('Xml', $result));
|
||||||
$this->assertTrue(in_array('Cache', $result));
|
$this->assertTrue(in_array('Cache', $result));
|
||||||
$this->assertTrue(in_array('HttpSocket', $result));
|
$this->assertTrue(in_array('HttpSocket', $result));
|
||||||
|
|
||||||
|
$result = $this->Configure->listObjects('model');
|
||||||
|
$this->assertTrue(in_array('Model', $result));
|
||||||
|
|
||||||
|
$result = $this->Configure->listObjects('behavior');
|
||||||
|
$this->assertTrue(in_array('Tree', $result));
|
||||||
|
|
||||||
|
$result = $this->Configure->listObjects('controller');
|
||||||
|
$this->assertTrue(in_array('Pages', $result));
|
||||||
|
|
||||||
|
$result = $this->Configure->listObjects('component');
|
||||||
|
$this->assertTrue(in_array('Auth', $result));
|
||||||
|
|
||||||
|
$result = $this->Configure->listObjects('view');
|
||||||
|
$this->assertTrue(in_array('Media', $result));
|
||||||
|
|
||||||
|
$result = $this->Configure->listObjects('helper');
|
||||||
|
$this->assertTrue(in_array('Html', $result));
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
|
|
|
@ -27,6 +27,23 @@
|
||||||
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
*/
|
*/
|
||||||
uses('controller' . DS . 'scaffold');
|
uses('controller' . DS . 'scaffold');
|
||||||
|
class ScaffoldMockController extends Controller {
|
||||||
|
|
||||||
|
var $name = 'ScaffoldMock';
|
||||||
|
|
||||||
|
var $scaffold;
|
||||||
|
}
|
||||||
|
class ScaffoldMock extends CakeTestModel {
|
||||||
|
|
||||||
|
var $useTable = 'posts';
|
||||||
|
|
||||||
|
}
|
||||||
|
class TestScaffoldView extends ScaffoldView {
|
||||||
|
|
||||||
|
function testGetFilename($action) {
|
||||||
|
return $this->_getViewFileName($action);
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Short description for class.
|
* Short description for class.
|
||||||
*
|
*
|
||||||
|
@ -35,8 +52,21 @@ uses('controller' . DS . 'scaffold');
|
||||||
*/
|
*/
|
||||||
class ScaffoldTest extends CakeTestCase {
|
class ScaffoldTest extends CakeTestCase {
|
||||||
|
|
||||||
function skip() {
|
var $fixtures = array('core.post');
|
||||||
$this->skipif (true, 'ScaffoldTest not implemented');
|
|
||||||
|
function setUp() {
|
||||||
|
$this->Controller = new ScaffoldMockController();
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() {
|
||||||
|
unset($this->Controller);
|
||||||
|
}
|
||||||
|
function testGetViewFilename() {
|
||||||
|
$this->Controller->action = 'index';
|
||||||
|
$ScaffoldView =& new TestScaffoldView($this->Controller);
|
||||||
|
$result = $ScaffoldView->testGetFilename('index');
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'scaffolds' . DS . 'index.ctp';
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
165
cake/tests/cases/libs/view/theme.test.php
Normal file
165
cake/tests/cases/libs/view/theme.test.php
Normal file
|
@ -0,0 +1,165 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||||
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The Open Group Test Suite License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.cases.libs
|
||||||
|
* @since CakePHP(tm) v 1.2.0.4206
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
|
*/
|
||||||
|
uses('controller' . DS . 'controller', 'view'.DS.'theme');
|
||||||
|
|
||||||
|
class PostsController extends Controller {
|
||||||
|
var $name = 'Posts';
|
||||||
|
function index() {
|
||||||
|
$this->set('testData', 'Some test data');
|
||||||
|
$test2 = 'more data';
|
||||||
|
$test3 = 'even more data';
|
||||||
|
$this->set(compact('test2', 'test3'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestView extends ThemeView {
|
||||||
|
|
||||||
|
function renderElement($name, $params = array()) {
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getViewFileName($name = null) {
|
||||||
|
return $this->_getViewFileName($name);
|
||||||
|
}
|
||||||
|
function getLayoutFileName($name = null) {
|
||||||
|
return $this->_getLayoutFileName($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cakeError($name, $params) {
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short description for class.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.cases.libs
|
||||||
|
*/
|
||||||
|
class ViewTest extends UnitTestCase {
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
Router::reload();
|
||||||
|
$this->Controller = new Controller();
|
||||||
|
$this->PostsController = new PostsController();
|
||||||
|
$this->PostsController->index();
|
||||||
|
$this->ThemeView = new View($this->PostsController);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPluginGetTemplate() {
|
||||||
|
$this->Controller->plugin = 'test_plugin';
|
||||||
|
$this->Controller->name = 'TestPlugin';
|
||||||
|
$this->Controller->viewPath = 'test_plugin';
|
||||||
|
$this->Controller->action = 'index';
|
||||||
|
$this->Controller->theme = 'test_plugin_theme';
|
||||||
|
|
||||||
|
$ThemeView = new TestView($this->Controller);
|
||||||
|
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
|
||||||
|
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'themed' . DS . 'test_plugin_theme' . DS .'test_plugin' . DS .'index.ctp';
|
||||||
|
$result = $ThemeView->getViewFileName('index');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'themed' . DS . 'test_plugin_theme' . DS . 'layouts' . DS .'default.ctp';
|
||||||
|
$result = $ThemeView->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testGetTemplate() {
|
||||||
|
$this->Controller->plugin = null;
|
||||||
|
$this->Controller->name = 'Pages';
|
||||||
|
$this->Controller->viewPath = 'pages';
|
||||||
|
$this->Controller->action = 'display';
|
||||||
|
$this->Controller->params['pass'] = array('home');
|
||||||
|
|
||||||
|
$ThemeView = new TestView($this->Controller);
|
||||||
|
$ThemeView->theme = 'test_theme';
|
||||||
|
|
||||||
|
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
|
||||||
|
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS));
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'pages' . DS .'home.ctp';
|
||||||
|
$result = $ThemeView->getViewFileName('home');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'posts' . DS .'index.ctp';
|
||||||
|
$result = $ThemeView->getViewFileName('/posts/index');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'themed' . DS . 'test_theme' . DS . 'layouts' . DS .'default.ctp';
|
||||||
|
$result = $ThemeView->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$ThemeView->layoutPath = 'rss';
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'layouts' . DS . 'rss' . DS . 'default.ctp';
|
||||||
|
$result = $ThemeView->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$ThemeView->layoutPath = 'email' . DS . 'html';
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'layouts' . DS . 'email' . DS . 'html' . DS . 'default.ctp';
|
||||||
|
$result = $ThemeView->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testMissingView() {
|
||||||
|
$this->Controller->plugin = null;
|
||||||
|
$this->Controller->name = 'Pages';
|
||||||
|
$this->Controller->viewPath = 'pages';
|
||||||
|
$this->Controller->action = 'display';
|
||||||
|
$this->Controller->params['pass'] = array('home');
|
||||||
|
|
||||||
|
$ThemeView = new TestView($this->Controller);
|
||||||
|
|
||||||
|
$expected = 'missingView';
|
||||||
|
$result = $ThemeView->getViewFileName('does_not_exist');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function testMissingLayout() {
|
||||||
|
$this->Controller->plugin = null;
|
||||||
|
$this->Controller->name = 'Posts';
|
||||||
|
$this->Controller->viewPath = 'posts';
|
||||||
|
$this->Controller->layout = 'whatever';
|
||||||
|
|
||||||
|
$ThemeView = new TestView($this->Controller);
|
||||||
|
$expected = 'missingLayout';
|
||||||
|
$result = $ThemeView->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function tearDown() {
|
||||||
|
unset($this->ThemeView);
|
||||||
|
unset($this->PostsController);
|
||||||
|
unset($this->Controller);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
|
@ -43,6 +43,17 @@ class TestView extends View {
|
||||||
function renderElement($name, $params = array()) {
|
function renderElement($name, $params = array()) {
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getViewFileName($name = null) {
|
||||||
|
return $this->_getViewFileName($name);
|
||||||
|
}
|
||||||
|
function getLayoutFileName($name = null) {
|
||||||
|
return $this->_getLayoutFileName($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
function cakeError($name, $params) {
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,31 +66,113 @@ class ViewTest extends UnitTestCase {
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
$this->Controller = new Controller();
|
||||||
$this->PostsController = new PostsController();
|
$this->PostsController = new PostsController();
|
||||||
$this->PostsController->index();
|
$this->PostsController->index();
|
||||||
$this->view = new View($this->PostsController);
|
$this->View = new View($this->PostsController);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testPluginGetTemplate() {
|
||||||
|
$this->Controller->plugin = 'test_plugin';
|
||||||
|
$this->Controller->name = 'TestPlugin';
|
||||||
|
$this->Controller->viewPath = 'test_plugin';
|
||||||
|
$this->Controller->action = 'index';
|
||||||
|
|
||||||
|
$View = new TestView($this->Controller);
|
||||||
|
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
|
||||||
|
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS));
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS .'test_plugin' . DS .'index.ctp';
|
||||||
|
$result = $View->getViewFileName('index');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS .'test_plugin' . DS . 'views' . DS . 'layouts' . DS .'default.ctp';
|
||||||
|
$result = $View->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testGetTemplate() {
|
||||||
|
$this->Controller->plugin = null;
|
||||||
|
$this->Controller->name = 'Pages';
|
||||||
|
$this->Controller->viewPath = 'pages';
|
||||||
|
$this->Controller->action = 'display';
|
||||||
|
$this->Controller->params['pass'] = array('home');
|
||||||
|
|
||||||
|
$View = new TestView($this->Controller);
|
||||||
|
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
|
||||||
|
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS, TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS));
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'pages' . DS .'home.ctp';
|
||||||
|
$result = $View->getViewFileName('home');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS .'posts' . DS .'index.ctp';
|
||||||
|
$result = $View->getViewFileName('/posts/index');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'layouts' . DS .'default.ctp';
|
||||||
|
$result = $View->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$View->layoutPath = 'rss';
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS . 'layouts' . DS . 'rss' . DS . 'default.ctp';
|
||||||
|
$result = $View->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
$View->layoutPath = 'email' . DS . 'html';
|
||||||
|
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS . 'layouts' . DS . 'email' . DS . 'html' . DS . 'default.ctp';
|
||||||
|
$result = $View->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testMissingView() {
|
||||||
|
$this->Controller->plugin = null;
|
||||||
|
$this->Controller->name = 'Pages';
|
||||||
|
$this->Controller->viewPath = 'pages';
|
||||||
|
$this->Controller->action = 'display';
|
||||||
|
$this->Controller->params['pass'] = array('home');
|
||||||
|
|
||||||
|
$View = new TestView($this->Controller);
|
||||||
|
|
||||||
|
$expected = 'missingView';
|
||||||
|
$result = $View->getViewFileName('does_not_exist');
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function testMissingLayout() {
|
||||||
|
$this->Controller->plugin = null;
|
||||||
|
$this->Controller->name = 'Posts';
|
||||||
|
$this->Controller->viewPath = 'posts';
|
||||||
|
$this->Controller->layout = 'whatever';
|
||||||
|
|
||||||
|
$View = new TestView($this->Controller);
|
||||||
|
$expected = 'missingLayout';
|
||||||
|
$result = $View->getLayoutFileName();
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testViewVars() {
|
function testViewVars() {
|
||||||
$this->assertEqual($this->view->viewVars, array('testData' => 'Some test data', 'test2' => 'more data', 'test3' => 'even more data'));
|
$this->assertEqual($this->View->viewVars, array('testData' => 'Some test data', 'test2' => 'more data', 'test3' => 'even more data'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testUUIDGeneration() {
|
function testUUIDGeneration() {
|
||||||
$result = $this->view->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
||||||
$this->assertEqual($result, 'form0425fe3bad');
|
$this->assertEqual($result, 'form0425fe3bad');
|
||||||
$result = $this->view->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
||||||
$this->assertEqual($result, 'forma9918342a7');
|
$this->assertEqual($result, 'forma9918342a7');
|
||||||
$result = $this->view->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
$result = $this->View->uuid('form', array('controller' => 'posts', 'action' => 'index'));
|
||||||
$this->assertEqual($result, 'form3ecf2e3e96');
|
$this->assertEqual($result, 'form3ecf2e3e96');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testAddInlineScripts() {
|
function testAddInlineScripts() {
|
||||||
$this->view->addScript('prototype.js');
|
$this->View->addScript('prototype.js');
|
||||||
$this->view->addScript('prototype.js');
|
$this->View->addScript('prototype.js');
|
||||||
$this->assertEqual($this->view->__scripts, array('prototype.js'));
|
$this->assertEqual($this->View->__scripts, array('prototype.js'));
|
||||||
|
|
||||||
$this->view->addScript('mainEvent', 'Event.observe(window, "load", function() { doSomething(); }, true);');
|
$this->View->addScript('mainEvent', 'Event.observe(window, "load", function() { doSomething(); }, true);');
|
||||||
$this->assertEqual($this->view->__scripts, array('prototype.js', 'mainEvent' => 'Event.observe(window, "load", function() { doSomething(); }, true);'));
|
$this->assertEqual($this->View->__scripts, array('prototype.js', 'mainEvent' => 'Event.observe(window, "load", function() { doSomething(); }, true);'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function testElementCache() {
|
function testElementCache() {
|
||||||
|
@ -124,8 +217,10 @@ class ViewTest extends UnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
unset($this->view);
|
unset($this->View);
|
||||||
unset($this->PostsController);
|
unset($this->PostsController);
|
||||||
|
unset($this->Controller);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
45
cake/tests/groups/view.group.php
Normal file
45
cake/tests/groups/view.group.php
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
* Short description for file.
|
||||||
|
*
|
||||||
|
* Long description for file
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
||||||
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The Open Group Test Suite License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
* @since CakePHP(tm) v 1.2.0.4206
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
||||||
|
*/
|
||||||
|
/** AllCoreHelpersGroupTest
|
||||||
|
*
|
||||||
|
* This test group will run all test in the cases/libs/view/helpers directory.
|
||||||
|
*
|
||||||
|
* @package cake.tests
|
||||||
|
* @subpackage cake.tests.groups
|
||||||
|
*/
|
||||||
|
class AllCoreViewsGroupTest extends GroupTest {
|
||||||
|
|
||||||
|
var $label = 'All core views';
|
||||||
|
|
||||||
|
function AllCoreViewsGroupTest() {
|
||||||
|
TestManager::addTestFile($this, CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'view',
|
||||||
|
CORE_TEST_CASES . DS . 'libs' . DS . 'view' . DS . 'theme');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
0
cake/tests/test_app/controllers/components/empty
Executable file
0
cake/tests/test_app/controllers/components/empty
Executable file
0
cake/tests/test_app/models/behaviors/empty
Executable file
0
cake/tests/test_app/models/behaviors/empty
Executable file
0
cake/tests/test_app/models/datasources/empty
Executable file
0
cake/tests/test_app/models/datasources/empty
Executable file
|
@ -0,0 +1 @@
|
||||||
|
test plugin default layout
|
|
@ -0,0 +1 @@
|
||||||
|
test plugin index
|
|
@ -0,0 +1 @@
|
||||||
|
test_plugin test_plugin_theme default layout
|
|
@ -0,0 +1 @@
|
||||||
|
test plugin index theme view
|
0
cake/tests/test_app/vendors/shells/tasks/empty
vendored
Executable file
0
cake/tests/test_app/vendors/shells/tasks/empty
vendored
Executable file
0
cake/tests/test_app/vendors/shells/templates/empty
vendored
Executable file
0
cake/tests/test_app/vendors/shells/templates/empty
vendored
Executable file
0
cake/tests/test_app/views/elements/empty
Executable file
0
cake/tests/test_app/views/elements/empty
Executable file
0
cake/tests/test_app/views/errors/empty
Executable file
0
cake/tests/test_app/views/errors/empty
Executable file
0
cake/tests/test_app/views/helpers/empty
Executable file
0
cake/tests/test_app/views/helpers/empty
Executable file
27
cake/tests/test_app/views/layouts/ajax.ctp
Executable file
27
cake/tests/test_app/views/layouts/ajax.ctp
Executable file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.view.templates.layouts
|
||||||
|
* @since CakePHP(tm) v 0.10.0.1076
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<?php echo $content_for_layout; ?>
|
68
cake/tests/test_app/views/layouts/default.ctp
Executable file
68
cake/tests/test_app/views/layouts/default.ctp
Executable file
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.view.templates.pages
|
||||||
|
* @since CakePHP(tm) v 0.10.0.1076
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title>
|
||||||
|
<?php __('CakePHP: the rapid development php framework:'); ?>
|
||||||
|
<?php echo $title_for_layout;?>
|
||||||
|
</title>
|
||||||
|
|
||||||
|
<?php echo $html->charset();?>
|
||||||
|
|
||||||
|
<link rel="icon" href="<?php echo $this->webroot;?>favicon.ico" type="image/x-icon" />
|
||||||
|
<link rel="shortcut icon" href="<?php echo $this->webroot;?>favicon.ico" type="image/x-icon" />
|
||||||
|
<?php echo $html->css('cake.generic');?>
|
||||||
|
<?php echo $scripts_for_layout;?>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="container">
|
||||||
|
<div id="header">
|
||||||
|
<h1><?php echo $html->link(__('CakePHP: the rapid development php framework', true), 'http://cakephp.org');?></h1>
|
||||||
|
</div>
|
||||||
|
<div id="content">
|
||||||
|
<?php
|
||||||
|
if ($session->check('Message.flash')):
|
||||||
|
$session->flash();
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
|
||||||
|
<?php echo $content_for_layout;?>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="footer">
|
||||||
|
<?php echo $html->link(
|
||||||
|
$html->image('cake.power.gif', array('alt'=> __("CakePHP: the rapid development php framework", true), 'border'=>"0")),
|
||||||
|
'http://www.cakephp.org/',
|
||||||
|
array('target'=>'_new'), null, false
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php echo $cakeDebug?>
|
||||||
|
</body>
|
||||||
|
</html>
|
45
cake/tests/test_app/views/layouts/flash.ctp
Executable file
45
cake/tests/test_app/views/layouts/flash.ctp
Executable file
|
@ -0,0 +1,45 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.libs.view.templates.layouts
|
||||||
|
* @since CakePHP(tm) v 0.10.0.1076
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title><?php echo $page_title?></title>
|
||||||
|
<?php echo $html->charset(); ?>
|
||||||
|
|
||||||
|
<?php if (Configure::read() == 0) { ?>
|
||||||
|
<meta http-equiv="Refresh" content="<?php echo $pause?>;url=<?php echo $url?>"/>
|
||||||
|
<?php } ?>
|
||||||
|
<style><!--
|
||||||
|
P { text-align:center; font:bold 1.1em sans-serif }
|
||||||
|
A { color:#444; text-decoration:none }
|
||||||
|
A:HOVER { text-decoration: underline; color:#44E }
|
||||||
|
--></style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p><a href="<?php echo $url?>"><?php echo $message?></a></p>
|
||||||
|
</body>
|
||||||
|
</html>
|
2
cake/tests/test_app/views/layouts/js/default.ctp
Executable file
2
cake/tests/test_app/views/layouts/js/default.ctp
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
<?php echo $scripts_for_layout; ?>
|
||||||
|
<script type="text/javascript"><?php echo $content_for_layout; ?></script>
|
17
cake/tests/test_app/views/layouts/rss/default.ctp
Executable file
17
cake/tests/test_app/views/layouts/rss/default.ctp
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
echo $rss->header();
|
||||||
|
|
||||||
|
if (!isset($channel)) {
|
||||||
|
$channel = array();
|
||||||
|
}
|
||||||
|
if (!isset($channel['title'])) {
|
||||||
|
$channel['title'] = $title_for_layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $rss->document(
|
||||||
|
$rss->channel(
|
||||||
|
array(), $channel, $content_for_layout
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
?>
|
2
cake/tests/test_app/views/layouts/xml/default.ctp
Executable file
2
cake/tests/test_app/views/layouts/xml/default.ctp
Executable file
|
@ -0,0 +1,2 @@
|
||||||
|
<?php e($xml->header()); ?>
|
||||||
|
<?php echo $content_for_layout; ?>
|
0
cake/tests/test_app/views/pages/empty
Executable file
0
cake/tests/test_app/views/pages/empty
Executable file
80
cake/tests/test_app/views/pages/home.ctp
Normal file
80
cake/tests/test_app/views/pages/home.ctp
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
<h2>Sweet, "Test App" got Baked by CakePHP!</h2>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if(Configure::read() > 0):
|
||||||
|
Debugger::checkSessionKey();
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
if (is_writable(TMP)):
|
||||||
|
echo '<span class="notice success">';
|
||||||
|
__('Your tmp directory is writable.');
|
||||||
|
echo '</span>';
|
||||||
|
else:
|
||||||
|
echo '<span class="notice">';
|
||||||
|
__('Your tmp directory is NOT writable.');
|
||||||
|
echo '</span>';
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
$settings = Cache::settings();
|
||||||
|
if (!empty($settings)):
|
||||||
|
echo '<span class="notice success">';
|
||||||
|
echo sprintf(__('The %s is being used for caching. To change the config edit APP/config/core.php ', true), '<em>'. $settings['engine'] . 'Engine</em>');
|
||||||
|
echo '</span>';
|
||||||
|
else:
|
||||||
|
echo '<span class="notice">';
|
||||||
|
__('Your cache is NOT working. Please check the settings in APP/config/core.php');
|
||||||
|
echo '</span>';
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
$filePresent = null;
|
||||||
|
if (file_exists(CONFIGS . 'database.php')):
|
||||||
|
echo '<span class="notice success">';
|
||||||
|
__('Your database configuration file is present.');
|
||||||
|
$filePresent = true;
|
||||||
|
echo '</span>';
|
||||||
|
else:
|
||||||
|
echo '<span class="notice">';
|
||||||
|
__('Your database configuration file is NOT present.');
|
||||||
|
echo '<br/>';
|
||||||
|
__('Rename config/database.php.default to config/database.php');
|
||||||
|
echo '</span>';
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
if (!empty($filePresent)):
|
||||||
|
uses('model' . DS . 'connection_manager');
|
||||||
|
$db = ConnectionManager::getInstance();
|
||||||
|
$connected = $db->getDataSource('default');
|
||||||
|
?>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
if ($connected->isConnected()):
|
||||||
|
echo '<span class="notice success">';
|
||||||
|
__('Cake is able to connect to the database.');
|
||||||
|
echo '</span>';
|
||||||
|
else:
|
||||||
|
echo '<span class="notice">';
|
||||||
|
__('Cake is NOT able to connect to the database.');
|
||||||
|
echo '</span>';
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
<?php endif;?>
|
||||||
|
<h3><?php __('Editing this Page') ?></h3>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
echo sprintf(__('To change the content of this page, edit: %s
|
||||||
|
To change its layout, edit: %s
|
||||||
|
You can also add some CSS styles for your pages at: %s', true),
|
||||||
|
APP . 'views' . DS . 'pages' . DS . 'home.ctp.<br />', APP . 'views' . DS . 'layouts' . DS . 'default.ctp.<br />', APP . 'webroot' . DS . 'css');
|
||||||
|
?>
|
||||||
|
</p>
|
1
cake/tests/test_app/views/posts/index.ctp
Normal file
1
cake/tests/test_app/views/posts/index.ctp
Normal file
|
@ -0,0 +1 @@
|
||||||
|
posts index
|
0
cake/tests/test_app/views/scaffolds/empty
Executable file
0
cake/tests/test_app/views/scaffolds/empty
Executable file
|
@ -0,0 +1 @@
|
||||||
|
default test_theme layout
|
|
@ -0,0 +1 @@
|
||||||
|
posts index themed view
|
Loading…
Add table
Reference in a new issue