Merging changes into trunk

Revision: [1764]
Changed var $ds back to $db and var $source back to $table in beta.
Moved last error message out of the object class.                
Fixed PHP 4 error in home.thtml.

Revision: [1763]
Added changes made in model error handling lost in merge



git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1765 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-01-12 03:56:59 +00:00
parent 677a39a445
commit 3a971927d4
11 changed files with 171 additions and 158 deletions

View file

@ -479,7 +479,7 @@ class Controller extends Object
$model = $this->modelClass;
$modelKey = $this->modelKey;
$table = $this->{$model}->source;
$table = $this->{$model}->table;
$association = array_search($table,$this->{$model}->alias);
$objRegistryModel = ClassRegistry::getObject($modelKey);

View file

@ -357,7 +357,7 @@ class Scaffold extends Object {
}
$this->controllerClass->constructClasses();
if(isset($this->controllerClass->{$this->modelKey}->ds))
if(isset($this->controllerClass->{$this->modelKey}->db))
{
if($params['action'] === 'index' || $params['action'] === 'list' ||
$params['action'] === 'show' || $params['action'] === 'add' ||

View file

@ -197,6 +197,41 @@ class ErrorHandler extends Object
exit();
}
/**
* Renders the Missing Helper file web page.
*
*/
function missingHelperFile($params)
{
extract($params);
$this->controller->webroot = $webroot;
$this->controller->set(array('helper' => Inflector::camelize($file) . "Helper",
'file' => $file,
'title' => 'Missing Helper File'));
$this->controller->render('../errors/missingHelperFile');
exit();
}
/**
* Renders the Missing Helper class web page.
*
*/
function missingHelperClass($params)
{
extract($params);
$this->controller->webroot = $webroot;
$this->controller->set(array('helper' => Inflector::camelize($class) . "Helper",
'file' => Inflector::underscore($class),
'title' => 'Missing Helper Class'));
$this->controller->render('../errors/missingHelperClass');
exit();
}
/**
* Enter description here...
*
* @return unknown
*/
function _webroot()
{
$dispatcher =& new Dispatcher();

View file

@ -282,15 +282,15 @@ class DataSource extends Object
function describe ($model)
{
if (isset($this->__descriptions[$model->source]))
if (isset($this->__descriptions[$model->table]))
{
return $this->__descriptions[$model->source];
return $this->__descriptions[$model->table];
}
$cache = $this->__cacheDescription($model->source);
$cache = $this->__cacheDescription($model->table);
if ($cache !== null)
{
$this->__descriptions[$model->source] = &$cache;
$this->__descriptions[$model->table] = &$cache;
return $cache;
}
return null;

View file

@ -9,7 +9,7 @@
* PHP versions 4 and 5
*
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
* Copyright (c) 2005, Cake Software Foundation, Inc.
* Copyright (c) 2005, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
@ -102,8 +102,8 @@ class DboSource extends DataSource
}
/**
* Queries the database with given SQL statement, and obtains some metadata about the result
* (rows affected, timing, any errors, number of rows in resultset). The query is also logged.
* Queries the database with given SQL statement, and obtains some metadata about the result
* (rows affected, timing, any errors, number of rows in resultset). The query is also logged.
* If DEBUG is set, the log is shown all the time, else it is only shown on errors.
*
* @param string $sql
@ -169,7 +169,7 @@ class DboSource extends DataSource
}
/**
* Returns an array of all result rows for a given SQL query.
* Returns an array of all result rows for a given SQL query.
* Returns false if no rows matched.
*
* @param string $sql SQL statement
@ -275,7 +275,7 @@ class DboSource extends DataSource
}
/**
* Output information about an SQL query. The SQL statement, number of rows in resultset,
* Output information about an SQL query. The SQL statement, number of rows in resultset,
* and execution time in microseconds. If the query fails, and error is output instead.
*
* @param string $sql
@ -283,12 +283,12 @@ class DboSource extends DataSource
function showQuery($sql)
{
$error = $this->error;
if (strlen($sql)>200 && !$this->fullDebug)
{
$sql = substr($sql, 0, 200) .'[...]';
}
if ($this->debug || $error)
{
print("<p style=\"text-align:left\"><b>Query:</b> {$sql} <small>[Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]</small>");
@ -309,7 +309,7 @@ class DboSource extends DataSource
$values = array_values($model->data);
}
if($this->execute('INSERT INTO '.$model->source.' ('.join(',', $fields).') VALUES ('.join(',', $values).')'))
if($this->execute('INSERT INTO '.$model->table.' ('.join(',', $fields).') VALUES ('.join(',', $values).')'))
{
return true;
}
@ -361,7 +361,7 @@ class DboSource extends DataSource
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet, $recursive = 1)
{
//$external = (($linkModel->ds === $this) && $resultSet == null);
//$external = (($linkModel->db === $this) && $resultSet == null);
$query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet);
if ($query)
@ -400,7 +400,7 @@ class DboSource extends DataSource
{
// Generates primary query
$sql = 'SELECT ' . join(', ', $this->fields($queryData['fields'])) . ' FROM ';
$sql .= $this->name($model->source).' AS ';
$sql .= $this->name($model->table).' AS ';
$sql .= $this->name($model->name).' ' . join(' ', $queryData['joins']).' ';
$sql .= $this->conditions($queryData['conditions']).' '.$this->order($queryData['order']);
$sql .= ' '.$this->limit($queryData['limit']);
@ -422,7 +422,7 @@ class DboSource extends DataSource
{
return $assocData['finderQuery'];
}
$sql = 'SELECT * FROM '.$this->name($linkModel->source).' AS '.$alias;
$sql = 'SELECT * FROM '.$this->name($linkModel->table).' AS '.$alias;
$conditions = $queryData['conditions'];
$condition = $model->escapeField($assocData['foreignKey']);
$condition .= '={$__cake_foreignKey__$}';
@ -443,7 +443,7 @@ class DboSource extends DataSource
}
else
{
$sql = ' LEFT JOIN '.$this->name($linkModel->source);
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
$sql .= ' AS '.$this->name($alias).' ON '.$this->name($alias).'.';
$sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey);
$sql .= $this->conditions($assocData['conditions']);
@ -461,7 +461,7 @@ class DboSource extends DataSource
{
pr('external');
$conditions = $assocData['conditions'];
$sql = 'SELECT * FROM '.$this->name($linkModel->source).' AS '.$this->name($alias);
$sql = 'SELECT * FROM '.$this->name($linkModel->table).' AS '.$this->name($alias);
$condition = $linkModel->escapeField($assocData['foreignKey']);
$condition .= '={$__cake_id__$}';
@ -483,7 +483,7 @@ class DboSource extends DataSource
}
else
{
$sql = ' LEFT JOIN '.$this->name($linkModel->source);
$sql = ' LEFT JOIN '.$this->name($linkModel->table);
$sql .= ' AS ' . $this->name($alias) . ' ON ';
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
$sql .= '='.$linkModel->escapeField($linkModel->primaryKey);
@ -503,7 +503,7 @@ class DboSource extends DataSource
else
{
$conditions = $assocData['conditions'];
$sql = 'SELECT * FROM '.$this->name($linkModel->source).' AS ';
$sql = 'SELECT * FROM '.$this->name($linkModel->table).' AS ';
$sql .= $this->name($alias);
$cond = $this->name($alias).'.'.$this->name($assocData['foreignKey']);
@ -537,7 +537,7 @@ class DboSource extends DataSource
$alias = $this->name($alias);
$sql = 'SELECT '.join(', ', $this->fields($assocData['fields']));
$sql .= ' FROM '.$this->name($linkModel->source).' AS '.$alias;
$sql .= ' FROM '.$this->name($linkModel->table).' AS '.$alias;
$sql .= ' JOIN '.$joinTbl.' ON '.$joinTbl;
$sql .= '.'.$this->name($assocData['foreignKey']).'={$__cake_id__$}';
$sql .= ' AND '.$joinTbl.'.'.$this->name($assocData['associationForeignKey']);
@ -560,7 +560,7 @@ class DboSource extends DataSource
$updates[] = $this->name($field).'='.$this->value($value);
}
$sql = 'UPDATE '.$this->name($model->source).' AS '.$this->name($model->name);
$sql = 'UPDATE '.$this->name($model->table).' AS '.$this->name($model->name);
$sql .= ' SET '.join(',', $updates);
$sql .= ' WHERE '.$model->escapeField($model->primaryKey).'='.$this->value($model->getID());
@ -580,7 +580,7 @@ class DboSource extends DataSource
}
foreach ($model->id as $id)
{
$result = $this->execute('DELETE FROM '.$this->name($model->source).' WHERE '.$this->name($model->primaryKey).'='.$this->value($id));
$result = $this->execute('DELETE FROM '.$this->name($model->table).' WHERE '.$this->name($model->primaryKey).'='.$this->value($id));
}
if ($result)
{
@ -598,7 +598,7 @@ class DboSource extends DataSource
if (!strpos('.', $key))
{
return $this->name($model->source).'.'.$this->name($key);
return $this->name($model->table).'.'.$this->name($key);
}
return $key;
}

View file

@ -212,7 +212,7 @@ class DboMysql extends DboSource
}
$fields = false;
$cols = $this->query('DESC ' . $this->name($model->source));
$cols = $this->query('DESC ' . $this->name($model->table));
foreach ($cols as $column)
{
@ -228,7 +228,7 @@ class DboMysql extends DboSource
}
}
$this->__cacheDescription($model->source, $fields);
$this->__cacheDescription($model->table, $fields);
return $fields;
}

View file

@ -57,7 +57,7 @@ class Model extends Object
* @var string
* @access public
*/
var $dataSource = 'default';
var $useDbConfig = 'default';
/**
* The DataSource connection object that this Model uses
@ -65,7 +65,7 @@ class Model extends Object
* @var unknown_type
* @access public
*/
var $ds = null;
var $db = null;
/**
* Enter description here... Still used?
@ -114,7 +114,7 @@ class Model extends Object
* @var string
* @access public
*/
var $source = false;
var $table = false;
/**
* The name of the ID field for this Model.
@ -359,7 +359,7 @@ class Model extends Object
// --- PHP4 Only
function __call($method, $params, &$return)
{
$return = $this->ds->query($method, $params, $this);
$return = $this->db->query($method, $params, $this);
return true;
}
// --- PHP4 Only
@ -424,9 +424,9 @@ class Model extends Object
$this->{$className} = new $className();
}
$this->alias[$assoc] = $this->{$className}->source;
$this->tableToModel[$this->{$className}->source] = $className;
$this->modelToTable[$className] = $this->{$className}->source;
$this->alias[$assoc] = $this->{$className}->table;
$this->tableToModel[$this->{$className}->table] = $className;
$this->modelToTable[$className] = $this->{$className}->table;
}
/**
@ -456,17 +456,17 @@ class Model extends Object
$data = '*';
break;
case 'foreignKey':
$data = Inflector::singularize($this->source).'_id';
$data = Inflector::singularize($this->table).'_id';
if ($type == 'belongsTo')
{
$data = Inflector::singularize($this->{$class}->source).'_id';
$data = Inflector::singularize($this->{$class}->table).'_id';
}
break;
case 'associationForeignKey':
$data = Inflector::singularize($this->{$class}->source) . '_id';
$data = Inflector::singularize($this->{$class}->table) . '_id';
break;
case 'joinTable':
$tables = array($this->source, $this->{$class}->source);
$tables = array($this->table, $this->{$class}->table);
sort($tables);
$data = $tables[0].'_'.$tables[1];
break;
@ -487,24 +487,24 @@ class Model extends Object
*/
function setSource($tableName)
{
if($this->ds->isInterfaceSupported('listSources'))
if($this->db->isInterfaceSupported('listSources'))
{
if (!in_array(strtolower($tableName), $this->ds->listSources()))
if (!in_array(strtolower($tableName), $this->db->listSources()))
{
$this->missingTable($tableName);
exit();
return $this->cakeError('missingTable',array(array('className' => $this->name,
'table' => $tableName)));
}
else
{
$this->source = $tableName;
$this->tableToModel[$this->source] = $this->name;
$this->table = $tableName;
$this->tableToModel[$this->table] = $this->name;
$this->loadInfo();
}
}
else
{
$this->source = $tableName;
$this->tableToModel[$this->source] = $this->name;
$this->table = $tableName;
$this->tableToModel[$this->table] = $this->name;
$this->loadInfo();
}
}
@ -555,9 +555,9 @@ class Model extends Object
*/
function loadInfo ()
{
if (!is_object($this->_tableInfo) && $this->ds->isInterfaceSupported('describe'))
if (!is_object($this->_tableInfo) && $this->db->isInterfaceSupported('describe'))
{
$this->_tableInfo = new NeatArray($this->ds->describe($this));
$this->_tableInfo = new NeatArray($this->db->describe($this));
}
return $this->_tableInfo;
}
@ -601,7 +601,6 @@ class Model extends Object
*/
function setId ($id)
{
trigger_error('Deprecated function: use Model::read()', E_USER_WARNING);
$this->id = $id;
}
@ -611,7 +610,6 @@ class Model extends Object
*/
function findBySql ($sql)
{
trigger_error('Deprecated function: use Model::query()', E_USER_WARNING);
return $this->query($sql);
}
@ -639,8 +637,8 @@ class Model extends Object
if ($this->id)
{
$field = $this->ds->name($this->name).'.'.$this->ds->name($this->primaryKey);
return $this->find($field . ' = ' . $this->ds->value($id), $fields);
$field = $this->db->name($this->name).'.'.$this->db->name($this->primaryKey);
return $this->find($field . ' = ' . $this->db->value($id), $fields);
}
else
{
@ -664,7 +662,7 @@ class Model extends Object
if ($conditions)
{
$conditions = $this->ds->conditions($conditions);
$conditions = $this->db->conditions($conditions);
}
if ($data = $this->find($conditions, $name, $order))
@ -781,7 +779,7 @@ class Model extends Object
{
if(!empty($this->id))
{
if ($this->ds->update($this, $fields, $values))
if ($this->db->update($this, $fields, $values))
{
if(!empty($joined))
{
@ -792,14 +790,14 @@ class Model extends Object
}
else
{
return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->ds->value($this->id));
return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->db->value($this->id));
}
}
else
{
if($this->ds->create($this, $fields, $values))
if($this->db->create($this, $fields, $values))
{
$this->id = $this->ds->lastInsertId($this->source, $this->primaryKey);
$this->id = $this->db->lastInsertId($this->table, $this->primaryKey);
if(!empty($joined))
{
if(!$this->id > 0 && isset($newID))
@ -847,8 +845,8 @@ class Model extends Object
{
if(!empty($update))
{
$values[] = $this->ds->value($id);
$values[] = $this->ds->value($update);
$values[] = $this->db->value($id);
$values[] = $this->db->value($update);
$values = join(',', $values);
$newValues[] = '('.$values.')';
unset($values);
@ -865,10 +863,10 @@ class Model extends Object
$total = count($joinTable);
for ($count = 0; $count < $total; $count++)
{
$this->ds->query("DELETE FROM {$joinTable[$count]} WHERE $mainKey = '{$id}'");
$this->db->query("DELETE FROM {$joinTable[$count]} WHERE $mainKey = '{$id}'");
if(!empty($newValue[$count]))
{
$this->ds->query("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count]}");
$this->db->query("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count]}");
}
}
}
@ -900,7 +898,7 @@ class Model extends Object
if($this->beforeDelete())
{
if ($this->id && $this->ds->delete($this))
if ($this->id && $this->db->delete($this))
{
$this->afterDelete();
$this->id = false;
@ -925,7 +923,7 @@ class Model extends Object
{
$id = $id[0];
}
return $this->hasAny($this->escapeField($this->primaryKey).'='.$this->ds->value($id));
return $this->hasAny($this->escapeField($this->primaryKey).'='.$this->db->value($id));
}
return false;
}
@ -986,7 +984,7 @@ class Model extends Object
$limit_str = '';
if ($limit)
{
$limit_str = $this->ds->limit($limit, $offset);
$limit_str = $this->db->limit($limit, $offset);
}
$queryData = array(
@ -996,7 +994,7 @@ class Model extends Object
'limit' => $limit_str,
'order' => $order
);
return $this->afterFind($this->ds->read($this, $queryData, $recursive));
return $this->afterFind($this->db->read($this, $queryData, $recursive));
}
@ -1032,7 +1030,7 @@ class Model extends Object
$sql .= $limit_str;
$data = $this->ds->fetchAll($sql);
$data = $this->db->fetchAll($sql);
return $data;
}*/
@ -1045,7 +1043,7 @@ class Model extends Object
*/
function execute ($data)
{
$data = $this->ds->fetchAll($data);
$data = $this->db->fetchAll($data);
foreach ($data as $key => $value)
{
foreach ($this->tableToModel as $key1 => $value1)
@ -1137,8 +1135,8 @@ class Model extends Object
*/
function findNeighbours ($conditions, $field, $value)
{
@list($prev) = $this->findAll($conditions . ' AND ' . $this->ds->name($field) . ' < ' . $this->ds->value($value), $field, $this->ds->name($field) . ' DESC', 1);
@list($next) = Model::findAll($conditions . ' AND ' . $this->ds->name($field) . ' > ' . $this->ds->value($value), $field, $this->ds->name($field) . ' ASC', 1);
@list($prev) = Model::findAll($conditions . ' AND ' . $this->db->name($field) . ' < ' . $this->db->value($value), $field, $this->db->name($field) . ' DESC', 1);
@list($next) = Model::findAll($conditions . ' AND ' . $this->db->name($field) . ' > ' . $this->db->value($value), $field, $this->db->name($field) . ' ASC', 1);
if (isset($prev))
{
@ -1168,7 +1166,7 @@ class Model extends Object
function query ()
{
$params = func_get_args();
return call_user_func_array(array(&$this->ds, 'query'), $params);
return call_user_func_array(array(&$this->db, 'query'), $params);
}
/**
@ -1288,8 +1286,8 @@ class Model extends Object
{
$valuePath = '{n}.'.$this->name.'.'.$this->displayField;
}
$keys = $this->ds->getFieldValue($result, $keyPath);
$vals = $this->ds->getFieldValue($result, $valuePath);
$keys = $this->db->getFieldValue($result, $keyPath);
$vals = $this->db->getFieldValue($result, $valuePath);
return array_combine($keys, $vals);
}
@ -1300,7 +1298,7 @@ class Model extends Object
*/
function escapeField($field)
{
return $this->ds->name($this->name).'.'.$this->ds->name($field);
return $this->db->name($this->name).'.'.$this->db->name($field);
}
/**
* Returns the current record's ID
@ -1378,12 +1376,12 @@ class Model extends Object
{
if ($dataSource == null)
{
$dataSource = $this->dataSource;
$dataSource = $this->useDbConfig;
}
$this->ds =& ConnectionManager::getDataSource($dataSource);
if(empty($this->ds) || $this->ds == null || !is_object($this->ds))
$this->db =& ConnectionManager::getDataSource($dataSource);
if(empty($this->db) || $this->db == null || !is_object($this->db))
{
$this->missingConnection();
return $this->cakeError('missingConnection',array(array('className' => $this->name)));
}
}

View file

@ -57,7 +57,7 @@ class Model extends Object
* @var string
* @access public
*/
var $dataSource = 'default';
var $useDbConfig = 'default';
/**
* The DataSource connection object that this Model uses
@ -65,7 +65,7 @@ class Model extends Object
* @var unknown_type
* @access public
*/
var $ds = null;
var $db = null;
/**
* Enter description here... Still used?
@ -114,7 +114,7 @@ class Model extends Object
* @var string
* @access public
*/
var $source = false;
var $table = false;
/**
* The name of the ID field for this Model.
@ -358,7 +358,7 @@ class Model extends Object
*/
function __call($method, $params)
{
return $this->ds->query($method, $params, $this);
return $this->db->query($method, $params, $this);
}
/**
@ -421,9 +421,9 @@ class Model extends Object
$this->{$className} = new $className();
}
$this->alias[$assoc] = $this->{$className}->source;
$this->tableToModel[$this->{$className}->source] = $className;
$this->modelToTable[$className] = $this->{$className}->source;
$this->alias[$assoc] = $this->{$className}->table;
$this->tableToModel[$this->{$className}->table] = $className;
$this->modelToTable[$className] = $this->{$className}->table;
}
/**
@ -453,17 +453,17 @@ class Model extends Object
$data = '*';
break;
case 'foreignKey':
$data = Inflector::singularize($this->source).'_id';
$data = Inflector::singularize($this->table).'_id';
if ($type == 'belongsTo')
{
$data = Inflector::singularize($this->{$class}->source).'_id';
$data = Inflector::singularize($this->{$class}->table).'_id';
}
break;
case 'associationForeignKey':
$data = Inflector::singularize($this->{$class}->source) . '_id';
$data = Inflector::singularize($this->{$class}->table) . '_id';
break;
case 'joinTable':
$tables = array($this->source, $this->{$class}->source);
$tables = array($this->table, $this->{$class}->table);
sort($tables);
$data = $tables[0].'_'.$tables[1];
break;
@ -484,24 +484,24 @@ class Model extends Object
*/
function setSource($tableName)
{
if($this->ds->isInterfaceSupported('listSources'))
if($this->db->isInterfaceSupported('listSources'))
{
if (!in_array(strtolower($tableName), $this->ds->listSources()))
if (!in_array(strtolower($tableName), $this->db->listSources()))
{
$this->missingTable($tableName);
exit();
return $this->cakeError('missingTable',array(array('className' => $this->name,
'table' => $tableName)));
}
else
{
$this->source = $tableName;
$this->tableToModel[$this->source] = $this->name;
$this->table = $tableName;
$this->tableToModel[$this->table] = $this->name;
$this->loadInfo();
}
}
else
{
$this->source = $tableName;
$this->tableToModel[$this->source] = $this->name;
$this->table = $tableName;
$this->tableToModel[$this->table] = $this->name;
$this->loadInfo();
}
}
@ -552,9 +552,9 @@ class Model extends Object
*/
function loadInfo ()
{
if (!is_object($this->_tableInfo) && $this->ds->isInterfaceSupported('describe'))
if (!is_object($this->_tableInfo) && $this->db->isInterfaceSupported('describe'))
{
$this->_tableInfo = new NeatArray($this->ds->describe($this));
$this->_tableInfo = new NeatArray($this->db->describe($this));
}
return $this->_tableInfo;
}
@ -598,7 +598,6 @@ class Model extends Object
*/
function setId ($id)
{
trigger_error('Deprecated function: use Model::read()', E_USER_WARNING);
$this->id = $id;
}
@ -608,7 +607,6 @@ class Model extends Object
*/
function findBySql ($sql)
{
trigger_error('Deprecated function: use Model::query()', E_USER_WARNING);
return $this->query($sql);
}
@ -636,8 +634,8 @@ class Model extends Object
if ($this->id)
{
$field = $this->ds->name($this->name).'.'.$this->ds->name($this->primaryKey);
return $this->find($field . ' = ' . $this->ds->value($id), $fields);
$field = $this->db->name($this->name).'.'.$this->db->name($this->primaryKey);
return $this->find($field . ' = ' . $this->db->value($id), $fields);
}
else
{
@ -661,7 +659,7 @@ class Model extends Object
if ($conditions)
{
$conditions = $this->ds->conditions($conditions);
$conditions = $this->db->conditions($conditions);
}
if ($data = $this->find($conditions, $name, $order))
@ -778,7 +776,7 @@ class Model extends Object
{
if(!empty($this->id))
{
if ($this->ds->update($this, $fields, $values))
if ($this->db->update($this, $fields, $values))
{
if(!empty($joined))
{
@ -789,14 +787,14 @@ class Model extends Object
}
else
{
return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->ds->value($this->id));
return $this->hasAny($this->escapeField($this->primaryKey).' = '.$this->db->value($this->id));
}
}
else
{
if($this->ds->create($this, $fields, $values))
if($this->db->create($this, $fields, $values))
{
$this->id = $this->ds->lastInsertId($this->source, $this->primaryKey);
$this->id = $this->db->lastInsertId($this->table, $this->primaryKey);
if(!empty($joined))
{
if(!$this->id > 0 && isset($newID))
@ -844,8 +842,8 @@ class Model extends Object
{
if(!empty($update))
{
$values[] = $this->ds->value($id);
$values[] = $this->ds->value($update);
$values[] = $this->db->value($id);
$values[] = $this->db->value($update);
$values = join(',', $values);
$newValues[] = '('.$values.')';
unset($values);
@ -862,10 +860,10 @@ class Model extends Object
$total = count($joinTable);
for ($count = 0; $count < $total; $count++)
{
$this->ds->query("DELETE FROM {$joinTable[$count]} WHERE $mainKey = '{$id}'");
$this->db->query("DELETE FROM {$joinTable[$count]} WHERE $mainKey = '{$id}'");
if(!empty($newValue[$count]))
{
$this->ds->query("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count]}");
$this->db->query("INSERT INTO {$joinTable[$count]} ({$fields[$count]}) VALUES {$newValue[$count]}");
}
}
}
@ -897,7 +895,7 @@ class Model extends Object
if($this->beforeDelete())
{
if ($this->id && $this->ds->delete($this))
if ($this->id && $this->db->delete($this))
{
$this->afterDelete();
$this->id = false;
@ -922,7 +920,7 @@ class Model extends Object
{
$id = $id[0];
}
return $this->hasAny($this->escapeField($this->primaryKey).'='.$this->ds->value($id));
return $this->hasAny($this->escapeField($this->primaryKey).'='.$this->db->value($id));
}
return false;
}
@ -983,7 +981,7 @@ class Model extends Object
$limit_str = '';
if ($limit)
{
$limit_str = $this->ds->limit($limit, $offset);
$limit_str = $this->db->limit($limit, $offset);
}
$queryData = array(
@ -993,7 +991,7 @@ class Model extends Object
'limit' => $limit_str,
'order' => $order
);
return $this->afterFind($this->ds->read($this, $queryData, $recursive));
return $this->afterFind($this->db->read($this, $queryData, $recursive));
}
@ -1029,7 +1027,7 @@ class Model extends Object
$sql .= $limit_str;
$data = $this->ds->fetchAll($sql);
$data = $this->db->fetchAll($sql);
return $data;
}*/
@ -1042,7 +1040,7 @@ class Model extends Object
*/
function execute ($data)
{
$data = $this->ds->fetchAll($data);
$data = $this->db->fetchAll($data);
foreach ($data as $key => $value)
{
foreach ($this->tableToModel as $key1 => $value1)
@ -1134,8 +1132,8 @@ class Model extends Object
*/
function findNeighbours ($conditions, $field, $value)
{
@list($prev) = $this->findAll($conditions . ' AND ' . $this->ds->name($field) . ' < ' . $this->ds->value($value), $field, $this->ds->name($field) . ' DESC', 1);
@list($next) = Model::findAll($conditions . ' AND ' . $this->ds->name($field) . ' > ' . $this->ds->value($value), $field, $this->ds->name($field) . ' ASC', 1);
@list($prev) = Model::findAll($conditions . ' AND ' . $this->db->name($field) . ' < ' . $this->db->value($value), $field, $this->db->name($field) . ' DESC', 1);
@list($next) = Model::findAll($conditions . ' AND ' . $this->db->name($field) . ' > ' . $this->db->value($value), $field, $this->db->name($field) . ' ASC', 1);
if (isset($prev))
{
@ -1165,7 +1163,7 @@ class Model extends Object
function query ()
{
$params = func_get_args();
return call_user_func_array(array(&$this->ds, 'query'), $params);
return call_user_func_array(array(&$this->db, 'query'), $params);
}
/**
@ -1285,8 +1283,8 @@ class Model extends Object
{
$valuePath = '{n}.'.$this->name.'.'.$this->displayField;
}
$keys = $this->ds->getFieldValue($result, $keyPath);
$vals = $this->ds->getFieldValue($result, $valuePath);
$keys = $this->db->getFieldValue($result, $keyPath);
$vals = $this->db->getFieldValue($result, $valuePath);
return array_combine($keys, $vals);
}
@ -1297,7 +1295,7 @@ class Model extends Object
*/
function escapeField($field)
{
return $this->ds->name($this->name).'.'.$this->ds->name($field);
return $this->db->name($this->name).'.'.$this->db->name($field);
}
@ -1377,12 +1375,12 @@ class Model extends Object
{
if ($dataSource == null)
{
$dataSource = $this->dataSource;
$dataSource = $this->useDbConfig;
}
$this->ds =& ConnectionManager::getDataSource($dataSource);
if(empty($this->ds) || $this->ds == null || !is_object($this->ds))
$this->db =& ConnectionManager::getDataSource($dataSource);
if(empty($this->db) || $this->db == null || !is_object($this->db))
{
$this->missingConnection();
return $this->cakeError('missingConnection',array(array('className' => $this->name)));
}
}

View file

@ -141,31 +141,12 @@ class Object
}
/**
* Renders the Missing Helper file web page.
* Enter description here...
*
* @param unknown_type $method
* @param unknown_type $messages
* @return unknown
*/
function missingHelperFile($file)
{
$this->missingHelperFile = $file;
$this->missingHelperClass = Inflector::camelize($file) . "Helper";
$this->pageTitle = 'Missing Helper File';
$this->render('../errors/missingHelperFile');
exit();
}
/**
* Renders the Missing Helper class web page.
*
*/
function missingHelperClass($class)
{
$this->missingHelperClass = Inflector::camelize($class) . "Helper";
$this->missingHelperFile = Inflector::underscore($class);
$this->pageTitle = 'Missing Helper Class';
$this->render('../errors/missingHelperClass');
exit();
}
function cakeError($method, $messages)
{
if(!class_exists('ErrorHandler'))

View file

@ -30,8 +30,9 @@
?>
<p style="background:#DBA941;padding:4px;font-size: 16px;">Your database configuration file is <?php echo file_exists(CONFIGS.'database.php') ?' present.' . $filePresent = ' ' : ' not present.'; ?></p>
<?php $db = ConnectionManager::getInstance(); ?>
<?php $connected = $db->getDataSource('default'); ?>
<?php if (!empty($filePresent)):?>
<p style="background:#DBA941;padding:4px;font-size: 16px;">Cake<?php echo $db->getDataSource('default')->connected ? ' is able to' : ' is not able to';?> connect to the database.</p>
<p style="background:#DBA941;padding:4px;font-size: 16px;">Cake<?php echo $connected->connected ? ' is able to' : ' is not able to';?> connect to the database.</p>
<br />
<?php endif; ?>
<h1>Take a bite out of Cake<em>PHP</em> Beta</h1>

View file

@ -46,10 +46,10 @@
$displayField = $otherModelObject->getDisplayField();
$displayText = $data[$alias][$displayField];
if(!empty($data[$objModel->tableToModel[$objModel->source]][$field]))
if(!empty($data[$objModel->tableToModel[$objModel->table]][$field]))
{
echo "<dd>".$html->link($displayText, '/'.Inflector::underscore($value['controller']).'/show/'
.$data[$objModel->tableToModel[$objModel->source]][$field] )."</dd>";
.$data[$objModel->tableToModel[$objModel->table]][$field] )."</dd>";
}
else
{
@ -59,9 +59,9 @@
else
{
// this is just a plain old field.
if( !empty($data[$objModel->tableToModel[$objModel->source]][$field]))
if( !empty($data[$objModel->tableToModel[$objModel->table]][$field]))
{
echo "<dd>".$data[$objModel->tableToModel[$objModel->source]][$field]."</dd>";
echo "<dd>".$data[$objModel->tableToModel[$objModel->table]][$field]."</dd>";
}
else
{
@ -74,8 +74,8 @@
</dl>
<ul class='actions'>
<?php
echo "<li>".$html->link('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->source]][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->source]][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->table]][$this->controller->{$modelName}->primaryKey])."</li>";
echo "<li>".$html->link('List '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/index')."</li>";
echo "<li>".$html->link('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/add')."</li>";
@ -94,7 +94,7 @@
foreach ($objModel->hasOne as $association => $relation)
{
$model = $relation['className'];
$otherModelName = $objModel->tableToModel[$objModel->{$model}->source];
$otherModelName = $objModel->tableToModel[$objModel->{$model}->table];
$controller = Inflector::pluralize($model);
echo "<div class='related'><H2>Related ".Inflector::humanize($association)."</H2>";