Merging fixes and enhancements into trunk.

Revision: [2151]
Merging changes made to model_php5.php into model_php4.php.

Revision: [2150]
Cleaning up code, removing in line comments

Revision: [2149]
Fixed wrong params passed to SessionComponent::setFlash() in Scaffold class.
Changed View::_render() to only suppress errors in the view when DEBUG is set to 0.

Revision: [2148]
Adding suggestion from Ticket #446.

Revision: [2147]
Added fix for Ticket #443

Revision: [2146]
Added fix for Ticket #444.
Added table.field in the CakeSession class database methods

Revision: [2145]
Renamed _new to _blank in default.thtml.
Starting to refactor changes that broke self joined associations.

Revision: [2144]
Adding fix for Ticket #202

Revision: [2143]
Adding support for nested array-based conditions

Revision: [2141]
Updating View for Session flash changes

Revision: [2140]
Adding Session flash enhancements for a ticket that I took but can't find because someone else closed it

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2152 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-02-28 07:35:01 +00:00
parent f37dfb6302
commit 6cc1cf8b80
13 changed files with 223 additions and 133 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ // // +---------------------------------------------------------------------------------------------------+ //
/////////////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////
0.10.8.2134 0.10.8.2152

View file

@ -132,41 +132,52 @@ class SessionComponent extends Object
* *
* Use like this. $this->Session->setFlash('This has been saved'); * Use like this. $this->Session->setFlash('This has been saved');
* *
* @param string $flashMessage Message to be flashed
* @param string $layout Layout to wrap flash message in
* @param array $params Parameters to be sent to layout as view variables
* @param string $key Message key, default is 'flash'
* @return string Last session error * @return string Last session error
*/ */
function setFlash($flashMessage) function setFlash($flashMessage, $layout = 'default', $params = array(), $key = 'flash')
{ {
$this->write('Message.flash', $flashMessage); if ($layout == 'default' || $layout == null)
{
$out = '<div class="message">'.$flashMessage.'</div>';
}
else if($layout == '')
{
$out = $flashMessage;
}
else
{
$ctrl = null;
$view = new View($ctrl);
$view->layout = $layout;
$view->pageTitle = '';
$view->_viewVars = $params;
$out = $view->renderLayout($flashMessage);
}
$this->write('Message.'.$key, $out);
} }
/** /**
* Used to output or return the value of the Message flash. * Use like this. $this->Session->flash();
* *
* @param string $css css class used in the div tag * @param string $key Optional message key
* @param boolean $return setting to true return the value of the flash message instead of displaying * @return null
* @return message output */
* */ function flash($key = 'flash')
function flash($css = 'message', $return = false)
{ {
if($this->check('Message.flash')) if($this->check('Message.'.$key))
{ {
if($return === false) e($this->read('Message.'.$key));
{ $this->del('Message.'.$key);
echo '<div class="'.$css.'">'.$this->read('Message.flash').'</div>';
$this->del('Message.flash');
return;
}
else
{
$return = $this->read('Message.flash');
$this->del('Message.flash');
return $return;
}
} }
else else
{ {
return false; return false;
} }
} }
/** /**

View file

@ -265,7 +265,7 @@ class Scaffold extends Object {
{ {
if(is_object($this->controllerClass->Session)) if(is_object($this->controllerClass->Session))
{ {
$this->controllerClass->Session->setFlash('The '.Inflector::humanize($this->modelKey).' has been '.$success.'.', '/'); $this->controllerClass->Session->setFlash('The '.Inflector::humanize($this->modelKey).' has been '.$success.'.');
$this->controllerClass->redirect(Inflector::underscore($this->controllerClass->viewPath)); $this->controllerClass->redirect(Inflector::underscore($this->controllerClass->viewPath));
} }
else else
@ -278,7 +278,7 @@ class Scaffold extends Object {
{ {
if(is_object($this->controllerClass->Session)) if(is_object($this->controllerClass->Session))
{ {
$this->controllerClass->Session->setFlash('Please correct errors below'); $this->controllerClass->Session->setFlash('Please correct errors below.');
} }
$this->controllerClass->set('data', $this->controllerClass->params['data']); $this->controllerClass->set('data', $this->controllerClass->params['data']);
$this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames($this->__rebuild($this->controllerClass->params['data']))); $this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames($this->__rebuild($this->controllerClass->params['data'])));
@ -320,7 +320,7 @@ class Scaffold extends Object {
{ {
if(is_object($this->controllerClass->Session)) if(is_object($this->controllerClass->Session))
{ {
$this->controllerClass->Session->setFlash('The '.Inflector::humanize($this->modelKey).' with id: '.$id.' has been deleted.', '/'); $this->controllerClass->Session->setFlash('The '.Inflector::humanize($this->modelKey).' with id: '.$id.' has been deleted.');
$this->controllerClass->redirect(Inflector::underscore($this->controllerClass->viewPath)); $this->controllerClass->redirect(Inflector::underscore($this->controllerClass->viewPath));
} }
else else
@ -333,7 +333,7 @@ class Scaffold extends Object {
{ {
if(is_object($this->controllerClass->Session)) if(is_object($this->controllerClass->Session))
{ {
$this->controllerClass->Session->setFlash('There was an error deleting the '.Inflector::humanize($this->modelKey).' with the id '.$id, '/'); $this->controllerClass->Session->setFlash('There was an error deleting the '.Inflector::humanize($this->modelKey).' with the id '.$id);
$this->controllerClass->redirect(Inflector::underscore($this->controllerClass->viewPath)); $this->controllerClass->redirect(Inflector::underscore($this->controllerClass->viewPath));
} }
else else

View file

@ -398,6 +398,25 @@ class DataSource extends Object
return false; return false;
} }
/**
* Formats column data from definition in DBO's $columns array
*
* @param string $data
* @param unknown_type $fields
* @return mixed Data formatted to column specifications
* @access protected
*/
function __formatColumnData($data, $format, $formatter)
{
switch($formatter)
{
case 'date':
return date($format, strtotime($data));
case 'sprintf':
return sprintf($format, $data);
}
}
/** /**
* Enter description here... * Enter description here...
* *

View file

@ -566,6 +566,10 @@ class DboSource extends DataSource
return true; return true;
} }
} }
elseif (isset($linkModel))
{
return $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet);
}
else else
{ {
if(isset($this->__assocJoins)) if(isset($this->__assocJoins))
@ -670,7 +674,7 @@ class DboSource extends DataSource
$sql .= $this->limit($queryData['limit']); $sql .= $this->limit($queryData['limit']);
return $sql; return $sql;
} }
else if($joinedOnSelf != true) else
{ {
if(!isset($assocData['fields'])) if(!isset($assocData['fields']))
{ {
@ -737,7 +741,7 @@ class DboSource extends DataSource
} }
return $sql; return $sql;
} }
else if($joinedOnSelf != true) else
{ {
if(!isset($assocData['fields'])) if(!isset($assocData['fields']))
{ {
@ -1060,15 +1064,25 @@ class DboSource extends DataSource
else else
{ {
$clause = 'WHERE '; $clause = 'WHERE ';
$out = array(); $out = $this->conditionKeysToString($conditions);
$count = 0; return $clause . ' ('.join(') AND (', $out).')';
$operator = null; }
foreach ($conditions as $key => $value) }
function conditionKeysToString($conditions)
{
$out = array();
$operator = null;
$bool = array('and', 'or', 'and not', 'or not');
foreach ($conditions as $key => $value)
{
if (in_array(low($key), $bool))
{
$out[] = '('.join(') '.$key.' (', $this->conditionKeysToString($value)).')';
}
else
{ {
if($count > 0)
{
$operator = ' AND ';
}
if (is_array($value)) if (is_array($value))
{ {
$data = $key . ' IN ('; $data = $key . ' IN (';
@ -1093,7 +1107,6 @@ class DboSource extends DataSource
{ {
$match['operator'] = ' = '; $match['operator'] = ' = ';
} }
if (strpos($match['value'], '-!') === 0) if (strpos($match['value'], '-!') === 0)
{ {
$match['value'] = str_replace('-!', '', $match['value']); $match['value'] = str_replace('-!', '', $match['value']);
@ -1108,13 +1121,13 @@ class DboSource extends DataSource
$data = $this->name($key) . ' '.$match['operator'].' '. $match['value']; $data = $this->name($key) . ' '.$match['operator'].' '. $match['value'];
} }
} }
$count++;
$out[] = $operator.$data; $out[] = $operator.$data;
} }
return $clause . join('', $out);
} }
return $out;
} }
/** /**
* To be overridden in subclasses. * To be overridden in subclasses.
* *
@ -1178,12 +1191,13 @@ class DboSource extends DataSource
{ {
$direction = $match['direction']; $direction = $match['direction'];
$keys = preg_replace('/'.$match['direction'].'/', '', $keys); $keys = preg_replace('/'.$match['direction'].'/', '', $keys);
return ' ORDER BY '.$keys.$direction;
} }
else else
{ {
$direction = ' '.$direction; $direction = ' '.$direction;
} }
return ' ORDER BY '.$this->name($keys).$direction; return ' ORDER BY '.$keys.$direction;
} }
} }

View file

@ -87,11 +87,11 @@ class DboMysql extends DboSource
'string' => array('name' => 'varchar', 'limit' => '255'), 'string' => array('name' => 'varchar', 'limit' => '255'),
'text' => array('name' => 'text'), 'text' => array('name' => 'text'),
'integer' => array('name' => 'int', 'limit' => '11'), 'integer' => array('name' => 'int', 'limit' => '11'),
'float' => array('name' => 'float'), 'float' => array('name' => 'float'),
'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s'), 'datetime' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s', 'formatter' => 'date'),
'timestamp' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s'), 'timestamp' => array('name' => 'datetime', 'format' => 'Y-m-d h:i:s', 'formatter' => 'date'),
'time' => array('name' => 'time', 'format' => 'h:i:s'), 'time' => array('name' => 'time', 'format' => 'h:i:s', 'formatter' => 'date'),
'date' => array('name' => 'date', 'format' => 'Y-m-d'), 'date' => array('name' => 'date', 'format' => 'Y-m-d', 'formatter' => 'date'),
'binary' => array('name' => 'blob'), 'binary' => array('name' => 'blob'),
'boolean' => array('name' => 'tinyint', 'limit' => '1')); 'boolean' => array('name' => 'tinyint', 'limit' => '1'));
@ -503,6 +503,16 @@ class DboMysql extends DboSource
return null; return null;
} }
/**
* Enter description here...
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
*/
function column($real)
{
return $real;
}
/** /**
* Enter description here... * Enter description here...
* *

View file

@ -640,7 +640,7 @@ class Model extends Object
$cols = array(); $cols = array();
foreach($columns as $col) { foreach($columns as $col) {
$cols[$col['name']] = $col['type']; $cols[$col['name']] = $this->db->column($col['type']);
} }
return $cols; return $cols;
} }
@ -888,7 +888,7 @@ class Model extends Object
} }
else else
{ {
return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->db->value($this->id)); return false;
} }
} }
else else
@ -1095,7 +1095,6 @@ class Model extends Object
} }
} }
/** /**
* Returns true if a record with set id exists. * Returns true if a record with set id exists.
* *
@ -1455,7 +1454,12 @@ class Model extends Object
*/ */
function generateList ($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null) function generateList ($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null)
{ {
$fields = array($this->primaryKey, $this->displayField); if ($keyPath == null && $valuePath == null)
{
$fields = array($this->primaryKey, $this->displayField);
} else {
$fields = '*';
}
$result = $this->findAll($conditions, $fields, $order, $limit, 1, 0); $result = $this->findAll($conditions, $fields, $order, $limit, 1, 0);
if ($keyPath == null) if ($keyPath == null)

View file

@ -636,7 +636,7 @@ class Model extends Object
$cols = array(); $cols = array();
foreach($columns as $col) { foreach($columns as $col) {
$cols[$col['name']] = $col['type']; $cols[$col['name']] = $this->db->column($col['type']);
} }
return $cols; return $cols;
} }
@ -884,7 +884,7 @@ class Model extends Object
} }
else else
{ {
return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->db->value($this->id)); return false;
} }
} }
else else
@ -1087,7 +1087,7 @@ class Model extends Object
{ {
foreach ($this->hasAndBelongsToMany as $assoc => $data) foreach ($this->hasAndBelongsToMany as $assoc => $data)
{ {
$this->db->execute("DELETE FROM {$this->db->name($data['joinTable'])} WHERE {$this->db->name($data['foreignKey'])} = '{$id}'"); $this->db->execute("DELETE FROM ".$this->db->name($data['joinTable'])." WHERE ".$this->db->name($data['foreignKey'])." = '{$id}'");
} }
} }
@ -1450,7 +1450,12 @@ class Model extends Object
*/ */
function generateList ($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null) function generateList ($conditions = null, $order = null, $limit = null, $keyPath = null, $valuePath = null)
{ {
$fields = array($this->primaryKey, $this->displayField); if ($keyPath == null && $valuePath == null)
{
$fields = array($this->primaryKey, $this->displayField);
} else {
$fields = '*';
}
$result = $this->findAll($conditions, $fields, $order, $limit, 1, 0); $result = $this->findAll($conditions, $fields, $order, $limit, 1, 0);
if ($keyPath == null) if ($keyPath == null)

View file

@ -133,17 +133,26 @@ class Object
{ {
uses('cake_log'); uses('cake_log');
} }
if (is_null($this->_log)) if (is_null($this->_log))
{ {
$this->_log = new CakeLog(); $this->_log = new CakeLog();
} }
if (!is_string($msg))
{
ob_start();
print_r($msg);
$msg = ob_get_contents();
ob_end_clean();
}
switch ($type) switch ($type)
{ {
case LOG_DEBUG: case LOG_DEBUG:
return $this->_log->write('debug', $msg); return $this->_log->write('debug', $msg);
default: break;
return $this->_log->write('error', $msg); default:
return $this->_log->write('error', $msg);
break;
} }
} }

View file

@ -296,7 +296,7 @@ class CakeSession extends Object
function __destroy($key) function __destroy($key)
{ {
$db =& ConnectionManager::getDataSource('default'); $db =& ConnectionManager::getDataSource('default');
$db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('id')." = ".$db->value($key)); $db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key));
return true; return true;
} }
@ -332,7 +332,7 @@ class CakeSession extends Object
function __gc($expires) function __gc($expires)
{ {
$db =& ConnectionManager::getDataSource('default'); $db =& ConnectionManager::getDataSource('default');
$db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('expires')." < " . $db->value(time())); $db->execute("DELETE FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.expires')." < " . $db->value(time()));
return true; return true;
} }
@ -501,7 +501,7 @@ class CakeSession extends Object
{ {
$db =& ConnectionManager::getDataSource('default'); $db =& ConnectionManager::getDataSource('default');
$row = $db->query("SELECT ".$db->name('data')." FROM ".$db->name('cake_sessions')." WHERE ".$db->name('id')." = ".$db->value($key)); $row = $db->query("SELECT ".$db->name('cake_sessions.data')." FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key));
if ($row && $row[0]['cake_sessions']['data']) if ($row && $row[0]['cake_sessions']['data'])
{ {
@ -634,15 +634,15 @@ class CakeSession extends Object
$expires = time() + CAKE_SESSION_TIMEOUT * $factor; $expires = time() + CAKE_SESSION_TIMEOUT * $factor;
$row = $db->query("SELECT COUNT(*) AS count FROM ".$db->name('cake_sessions')." WHERE ".$db->name('id')." = ".$db->value($key)); $row = $db->query("SELECT COUNT(id) AS count FROM ".$db->name('cake_sessions')." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key));
if($row[0][0]['count'] > 0) if($row[0][0]['count'] > 0)
{ {
$db->execute("UPDATE ".$db->name('cake_sessions')." SET ".$db->name('data')." = ".$db->value($value).", ".$db->name('expires')." = ".$db->value($expires)." WHERE ".$db->name('id')." = ".$db->value($key)); $db->execute("UPDATE ".$db->name('cake_sessions')." SET ".$db->name('cake_sessions.data')." = ".$db->value($value).", ".$db->name('cake_sessions.expires')." = ".$db->value($expires)." WHERE ".$db->name('cake_sessions.id')." = ".$db->value($key));
} }
else else
{ {
$db->execute("INSERT INTO ".$db->name('cake_sessions')." (".$db->name('data').",".$db->name('expires').",".$db->name('id').") VALUES (".$db->value($value).", ".$db->value($expires).", ".$db->value($key).")"); $db->execute("INSERT INTO ".$db->name('cake_sessions')." (".$db->name('cake_sessions.data').",".$db->name('cake_sessions.expires').",".$db->name('cake_sessions.id').") VALUES (".$db->value($value).", ".$db->value($expires).", ".$db->value($key).")");
} }
return true; return true;
} }

View file

@ -61,7 +61,7 @@ class AjaxHelper extends Helper
* *
* @var array * @var array
*/ */
var $ajaxOptions = array('type', 'confirm', 'condition', 'before', 'after', 'fallback', 'update', 'loading', 'loaded', 'interactive', 'complete', 'with', 'url', 'method', 'position', 'form', 'parameters', 'evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive'); var $ajaxOptions = array('type', 'confirm', 'condition', 'before', 'after', 'fallback', 'update', 'loading', 'loaded', 'interactive', 'complete', 'with', 'url', 'method', 'position', 'form', 'parameters', 'evalScripts', 'asynchronous', 'onComplete', 'onUninitialized', 'onLoading', 'onLoaded', 'onInteractive', 'insertion');
/** /**
* Options for draggable. * Options for draggable.

View file

@ -53,7 +53,7 @@
<br /> <br />
<p> <p>
<!--PLEASE USE ONE OF THE POWERED BY CAKEPHP LOGO--> <!--PLEASE USE ONE OF THE POWERED BY CAKEPHP LOGO-->
<a href="http://www.cakephp.org/" target="_new"> <a href="http://www.cakephp.org/" target="_blank">
<?php echo $html->image('cake.power.png', array('alt'=>'CakePHP : Rapid Development Framework', <?php echo $html->image('cake.power.png', array('alt'=>'CakePHP : Rapid Development Framework',
'height' => "15", 'height' => "15",
'width' => "80"))?> 'width' => "80"))?>

View file

@ -216,26 +216,29 @@ class View extends Object
*/ */
function __construct (&$controller) function __construct (&$controller)
{ {
$this->controller =& $controller; if ($controller != null)
$this->_viewVars =& $this->controller->_viewVars; {
$this->action =& $this->controller->action; $this->controller =& $controller;
$this->autoLayout =& $this->controller->autoLayout; $this->_viewVars =& $this->controller->_viewVars;
$this->autoRender =& $this->controller->autoRender; $this->action =& $this->controller->action;
$this->base =& $this->controller->base; $this->autoLayout =& $this->controller->autoLayout;
$this->webroot =& $this->controller->webroot; $this->autoRender =& $this->controller->autoRender;
$this->helpers =& $this->controller->helpers; $this->base =& $this->controller->base;
$this->here =& $this->controller->here; $this->webroot =& $this->controller->webroot;
$this->layout =& $this->controller->layout; $this->helpers =& $this->controller->helpers;
$this->modelNames =& $this->controller->modelNames; $this->here =& $this->controller->here;
$this->name =& $this->controller->name; $this->layout =& $this->controller->layout;
$this->pageTitle =& $this->controller->pageTitle; $this->modelNames =& $this->controller->modelNames;
$this->parent =& $this->controller->parent; $this->name =& $this->controller->name;
$this->viewPath =& $this->controller->viewPath; $this->pageTitle =& $this->controller->pageTitle;
$this->params =& $this->controller->params; $this->parent =& $this->controller->parent;
$this->data =& $this->controller->data; $this->viewPath =& $this->controller->viewPath;
$this->displayFields =& $this->controller->displayFields; $this->params =& $this->controller->params;
$this->webservices =& $this->controller->webservices; $this->data =& $this->controller->data;
$this->plugin =& $this->controller->plugin; $this->displayFields =& $this->controller->displayFields;
$this->webservices =& $this->controller->webservices;
$this->plugin =& $this->controller->plugin;
}
parent::__construct(); parent::__construct();
} }
@ -353,11 +356,11 @@ class View extends Object
{ {
if(substr($viewFileName, -5) === 'thtml') if(substr($viewFileName, -5) === 'thtml')
{ {
$out = View::_render($viewFileName, $this->_viewVars, 0); $out = View::_render($viewFileName, $this->_viewVars);
} }
else else
{ {
$out = $this->_render($viewFileName, $this->_viewVars, 0); $out = $this->_render($viewFileName, $this->_viewVars);
} }
if ($out !== false) if ($out !== false)
{ {
@ -370,7 +373,7 @@ class View extends Object
} }
else else
{ {
$out = $this->_render($viewFileName, $this->_viewVars, false); $out = $this->_render($viewFileName, $this->_viewVars);
trigger_error(sprintf(__("Error in view %s, got: <blockquote>%s</blockquote>"), $viewFileName, $out), E_USER_ERROR); trigger_error(sprintf(__("Error in view %s, got: <blockquote>%s</blockquote>"), $viewFileName, $out), E_USER_ERROR);
} }
return true; return true;
@ -399,7 +402,7 @@ class View extends Object
{ {
$fn = APP.'plugins'.DS.$this->plugin.'views'.DS.'elements'.DS.$name.$this->ext; $fn = APP.'plugins'.DS.$this->plugin.'views'.DS.'elements'.DS.$name.$this->ext;
$params = array_merge_recursive($params, $this->loaded); $params = array_merge_recursive($params, $this->loaded);
return $this->_render($fn, array_merge($this->_viewVars, $params), true, false); return $this->_render($fn, array_merge($this->_viewVars, $params), false);
} }
} }
@ -409,7 +412,12 @@ class View extends Object
} }
$params = array_merge_recursive($params, $this->loaded); $params = array_merge_recursive($params, $this->loaded);
return $this->_render($fn, array_merge($this->_viewVars, $params), true, false); return $this->_render($fn, array_merge($this->_viewVars, $params), false);
}
function element($name)
{
} }
/** /**
@ -422,35 +430,44 @@ class View extends Object
{ {
$layout_fn = $this->_getLayoutFileName(); $layout_fn = $this->_getLayoutFileName();
if(DEBUG > 2) if(DEBUG > 2 && $this->controller != null)
{ {
$debug = View::_render(LIBS.'view'.DS.'templates'.DS.'elements'.DS.'dump.thtml', array('controller' => $this->controller), true, false); $debug = View::_render(LIBS.'view'.DS.'templates'.DS.'elements'.DS.'dump.thtml', array('controller' => $this->controller), false);
} }
else else
{ {
$debug = ''; $debug = '';
} }
$data_for_layout = array_merge($this->_viewVars, array(
'title_for_layout'=>$this->pageTitle !== false? $this->pageTitle: Inflector::humanize($this->viewPath), if ($this->pageTitle !== false)
'content_for_layout'=>$content_for_layout, {
'cakeDebug' => $debug)); $pageTitle = $this->pageTitle;
}
else
{
$pageTitle = Inflector::humanize($this->viewPath);
}
$data_for_layout = array_merge($this->_viewVars, array('title_for_layout' => $pageTitle,
'content_for_layout'=> $content_for_layout,
'cakeDebug' => $debug));
if (is_file($layout_fn)) if (is_file($layout_fn))
{ {
$data_for_layout = array_merge($data_for_layout,$this->loaded); # load all view variables) $data_for_layout = array_merge($data_for_layout, $this->loaded);
if(substr($layout_fn, -5) === 'thtml') if(substr($layout_fn, -5) === 'thtml')
{ {
$out = View::_render($layout_fn, $data_for_layout, true, false); $out = View::_render($layout_fn, $data_for_layout, false);
} }
else else
{ {
$out = $this->_render($layout_fn, $data_for_layout, true, false); $out = $this->_render($layout_fn, $data_for_layout, false);
} }
if ($out === false) if ($out === false)
{ {
$out = $this->_render($layout_fn, $data_for_layout, false); $out = $this->_render($layout_fn, $data_for_layout);
trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>"), $layout_fn, $out), E_USER_ERROR); trigger_error(sprintf(__("Error in layout %s, got: <blockquote>%s</blockquote>"), $layout_fn, $out), E_USER_ERROR);
return false; return false;
} }
@ -550,7 +567,7 @@ class View extends Object
*/ */
function _getLayoutFileName() function _getLayoutFileName()
{ {
if(!is_null($this->webservices)) if(isset($this->webservices) && !is_null($this->webservices))
{ {
$type = strtolower($this->webservices).DS; $type = strtolower($this->webservices).DS;
} }
@ -559,7 +576,7 @@ class View extends Object
$type = null; $type = null;
} }
if(!is_null($this->plugin)) if(isset($this->plugin) && !is_null($this->plugin))
{ {
if(file_exists(APP.'plugins'.DS.$this->plugin.'views'.DS.'layouts'.DS.$this->layout.$this->ext)) if(file_exists(APP.'plugins'.DS.$this->plugin.'views'.DS.'layouts'.DS.$this->layout.$this->ext))
{ {
@ -586,11 +603,10 @@ 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
* @param boolean $___playSafe If set to false, the include() of the $__viewFn is done without suppressing output of errors
* @return string Rendered output * @return string Rendered output
* @access private * @access private
*/ */
function _render($___viewFn, $___dataForView, $___playSafe = true, $loadHelpers = true) function _render($___viewFn, $___dataForView, $loadHelpers = true)
{ {
if ($this->helpers != false && $loadHelpers === true) if ($this->helpers != false && $loadHelpers === true)
{ {
@ -615,27 +631,22 @@ class View extends Object
} }
} }
extract($___dataForView, EXTR_SKIP); # load all view variables extract($___dataForView, EXTR_SKIP);
/** $BASE = $this->base;
* Local template variables. $params = &$this->params;
*/ $page_title = $this->pageTitle;
$BASE = $this->base;
$params = &$this->params;
$page_title = $this->pageTitle;
/** ob_start();
* Start caching output (eval outputs directly so we need to cache). if(DEBUG)
*/ {
ob_start(); include($___viewFn);
}
/** else
* Include the template. {
*/ @include($___viewFn);
$___playSafe? @include($___viewFn): include($___viewFn); }
$out = ob_get_clean();
$out = ob_get_clean(); return $out;
return $out;
} }
/** /**
@ -693,12 +704,12 @@ class View extends Object
if(class_exists($helperCn)) if(class_exists($helperCn))
{ {
${$camelBackedHelper} =& new $helperCn; ${$camelBackedHelper} =& new $helperCn;
${$camelBackedHelper}->base = $this->base; ${$camelBackedHelper}->base = $this->base;
${$camelBackedHelper}->webroot = $this->webroot; ${$camelBackedHelper}->webroot = $this->webroot;
${$camelBackedHelper}->here = $this->here; ${$camelBackedHelper}->here = $this->here;
${$camelBackedHelper}->params = $this->params; ${$camelBackedHelper}->params = $this->params;
${$camelBackedHelper}->action = $this->action; ${$camelBackedHelper}->action = $this->action;
${$camelBackedHelper}->data = $this->data; ${$camelBackedHelper}->data = $this->data;
${$camelBackedHelper}->themeWeb = $this->themeWeb; ${$camelBackedHelper}->themeWeb = $this->themeWeb;
${$camelBackedHelper}->tags = $tags; ${$camelBackedHelper}->tags = $tags;
@ -724,6 +735,13 @@ class View extends Object
return $loaded; return $loaded;
} }
/**
* Enter description here...
*
* @param unknown_type $action
* @param unknown_type $layout
* @return unknown
*/
function pluginView($action, $layout) function pluginView($action, $layout)
{ {
$viewFileName = APP.'plugins'.DS.$this->plugin.'views'.DS.$this->viewPath.DS.$action.$this->ext; $viewFileName = APP.'plugins'.DS.$this->plugin.'views'.DS.$this->viewPath.DS.$action.$this->ext;