merging [880] [881] [882] and [883] fixes

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@884 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-09-18 13:25:20 +00:00
parent 7eb53efb5b
commit a86866a7a1
13 changed files with 231 additions and 169 deletions

View file

@ -75,7 +75,7 @@ class Cache extends Model {
*
* @var string
*/
var $use_table = 'cache';
var $useTable = 'cache';
/**
* Constructor. Generates an md5'ed id for internal use. Calls the constructor on Model as well.
@ -111,7 +111,7 @@ class Cache extends Model {
{
$data = addslashes($this->for_caching.$content);
$expire = date("Y-m-d H:i:s",time()+($keep_for>0? $keep_for: 999999999));
return $this->query("REPLACE {$this->use_table} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')");
return $this->query("REPLACE {$this->useTable} (id,data,expire) VALUES ('{$this->id}', '{$data}', '{$expire}')");
}
/**
@ -155,7 +155,7 @@ class Cache extends Model {
*/
function clear()
{
return $this->query("DELETE FROM {$this->use_table}");
return $this->query("DELETE FROM {$this->useTable}");
}
}

View file

@ -213,7 +213,7 @@ class Controller extends Object
* Enter description here...
*
*/
function contructClasses(){
function constructClasses(){
if(empty($this->params['pass']))
{
@ -261,6 +261,28 @@ class Controller extends Object
}
}
}
if (!empty($this->beforeFilter))
{
if(is_array($this->beforeFilter))
{
foreach($this->beforeFilter as $filter)
{
if(is_callable(array($this,$filter)))
{
$this->$filter();
}
}
}
else
{
if(is_callable(array($this,$this->beforeFilter)))
{
$this->{$this->beforeFilter}();
}
}
}
}
/**
@ -394,9 +416,9 @@ class Controller extends Object
* Renders the Missing Table web page.
*
*/
function missingTable($table_name)
function missingTable($tableName)
{
$this->missingTableName = $table_name;
$this->missingTableName = $tableName;
$this->pageTitle = 'Missing Database Table';
//We are simulating action call below, this is not a filename!
$this->render('../errors/missingTable');
@ -517,7 +539,7 @@ class Controller extends Object
$classRegistry =& ClassRegistry::getInstance();
$objRegistryModel = $classRegistry->getObject(Inflector::singularize($model));
foreach ($objRegistryModel->_table_info as $tables)
foreach ($objRegistryModel->_tableInfo as $tables)
{
foreach ($tables as $tabl)
{

View file

@ -129,12 +129,12 @@ class DBO_AdoDB extends DBO
/**
* Returns an array of the fields in given table name.
*
* @param string $table_name Name of database table to inspect
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function fields ($table_name)
function fields ($tableName)
{
$data = $this->_adodb->MetaColumns($table_name);
$data = $this->_adodb->MetaColumns($tableName);
$fields = false;
foreach ($data as $item)

View file

@ -89,7 +89,7 @@ class DBO_generic extends DBO
* Abstract method defined in subclasses.
*
*/
function fields ($table_name)
function fields ($tableName)
{
}

View file

@ -135,13 +135,13 @@ class DBO_MySQL extends DBO
/**
* Returns an array of the fields in given table name.
*
* @param string $table_name Name of database table to inspect
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function fields ($table_name)
function fields ($tableName)
{
$fields = false;
$cols = $this->all("DESC {$table_name}");
$cols = $this->all("DESC {$tableName}");
foreach ($cols as $column)
{

View file

@ -167,12 +167,12 @@ class DBO_Pear extends DBO
/**
* Returns an array of the fields in given table name.
*
* @param string $table_name Name of database table to inspect
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function fields ($table_name)
function fields ($tableName)
{
$data = $this->_pear->tableInfo($table_name);
$data = $this->_pear->tableInfo($tableName);
$fields = false;
foreach ($data as $item)

View file

@ -133,12 +133,12 @@ class DBO_Postgres extends DBO
/**
* Returns an array of the fields in given table name.
*
* @param string $table_name Name of database table to inspect
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function fields ($table_name)
function fields ($tableName)
{
$sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$table_name}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid";
$sql = "SELECT c.relname, a.attname, t.typname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname = '{$tableName}' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid";
$fields = false;
foreach ($this->all($sql) as $field) {

View file

@ -132,13 +132,13 @@ class DBO_SQLite extends DBO
/**
* Returns an array of the fields in given table name.
*
* @param string $table_name Name of database table to inspect
* @param string $tableName Name of database table to inspect
* @return array Fields in table. Keys are name and type
*/
function fields($table_name)
function fields($tableName)
{
$fields = false;
$cols = sqlite_fetch_column_types($table_name, $this->_conn);
$cols = sqlite_fetch_column_types($tableName, $this->_conn);
foreach ($cols as $column => $type)
{

View file

@ -161,7 +161,7 @@ class Dispatcher extends Object
}
}
$controller->contructClasses();
$controller->constructClasses();
if ($missingAction)
{

View file

@ -49,7 +49,7 @@ class JavascriptHelper extends Helper
*/
function codeBlock($script)
{
return sprintf($this->tags['javascriptBlock'], $script);
return sprintf($this->tags['javascriptblock'], $script);
}
/**
@ -60,7 +60,7 @@ class JavascriptHelper extends Helper
*/
function link($url)
{
return sprintf($this->tags['javascriptLink'], $this->base.$url);
return sprintf($this->tags['javascriptlink'], $this->base.$url);
}
/**
@ -71,7 +71,7 @@ class JavascriptHelper extends Helper
*/
function linkOut($url)
{
return sprintf($this->tags['javascriptLink'], $url);
return sprintf($this->tags['javascriptlink'], $url);
}
/**

View file

@ -193,12 +193,12 @@ class Inflector extends Object
/**
* Returns Cake class name ("Post" for the database table "posts".) for given database table.
*
* @param string $table_name Name of database table to get class name for
* @param string $tableName Name of database table to get class name for
* @return string
*/
function classify($table_name)
function classify($tableName)
{
return Inflector::camelize(Inflector::singularize($table_name));
return Inflector::camelize(Inflector::singularize($tableName));
}
/**

View file

@ -68,7 +68,7 @@ class Model extends Object
* @var string
* @access public
*/
var $use_table = false;
var $useTable = false;
/**
* Enter description here...
@ -100,7 +100,7 @@ class Model extends Object
* @var array
* @access private
*/
var $_table_info = null;
var $_tableInfo = null;
/**
* Enter description here...
@ -232,12 +232,12 @@ class Model extends Object
$this->id = $id;
}
$table_name = $table? $table: ($this->use_table? $this->use_table: Inflector::tableize(get_class($this)));
$tableName = $table? $table: ($this->useTable? $this->useTable: Inflector::tableize(get_class($this)));
//Table Prefix Hack - Check to see if the function exists.
if (in_array('settableprefix', get_class_methods(get_class($this)))) $this->setTablePrefix();
// Table Prefix Hack - Get the prefix for this view.
$this->tablePrefix? $this->useTable($this->tablePrefix.$table_name): $this->useTable ($table_name);
//$this->useTable ($table_name);
$this->tablePrefix? $this->useTable($this->tablePrefix.$tableName): $this->useTable ($tableName);
//$this->useTable ($tableName);
parent::__construct();
$this->createLinks();
}
@ -752,18 +752,18 @@ class Model extends Object
/**
* Sets a custom table for your controller class. Used by your controller to select a database table.
*
* @param string $table_name Name of the custom table
* @param string $tableName Name of the custom table
*/
function useTable ($table_name)
function useTable ($tableName)
{
if (!in_array(strtolower($table_name), $this->db->tables()))
if (!in_array(strtolower($tableName), $this->db->tables()))
{
$this->_throwMissingTable($table_name);
$this->_throwMissingTable($tableName);
die();
}
else
{
$this->table = $table_name;
$this->table = $tableName;
$this->loadInfo();
}
}
@ -845,11 +845,11 @@ class Model extends Object
*/
function loadInfo ()
{
if (empty($this->_table_info))
if (empty($this->_tableInfo))
{
$this->_table_info = new NeatArray($this->db->fields($this->table));
$this->_tableInfo = new NeatArray($this->db->fields($this->table));
}
return $this->_table_info;
return $this->_tableInfo;
}
/**
@ -861,11 +861,11 @@ class Model extends Object
*/
function hasField ($name)
{
if (empty($this->_table_info))
if (empty($this->_tableInfo))
{
$this->loadInfo();
}
return $this->_table_info->findIn('name', $name);
return $this->_tableInfo->findIn('name', $name);
}
/**
@ -1290,22 +1290,46 @@ class Model extends Object
if(!empty($this->_oneToMany))
{
$newValue = $this->_findOneToMany($data);
if(!empty($newValue))
{
$data = $newValue;
}
}
if(!empty($this->_manyToMany))
{
$newValue = $this->_findManyToMany($data);
if(!empty($newValue))
{
$data = $newValue;
}
}
return $data;
}
/**
* Enter description here...
*
* @param unknown_type $data
* @return unknown
*/
function _findOneToMany(&$data)
{
$datacheck = $data;
$original = $data;
foreach ($this->_oneToMany as $rule)
{
$count = 0;
list($table, $field, $value) = $rule;
foreach ($datacheck as $key => $value1)
{
foreach ($value1 as $key2 => $value2)
{
if($key2 === Inflector::singularize($this->table))
{
$oneToManySelect[$table] = $this->db->all("SELECT * FROM {$table} WHERE ($field) = '{$value2['id']}'");
$oneToManySelect[$table] = $this->db->all("SELECT * FROM {$table}
WHERE ($field) = '{$value2['id']}'");
if( !empty($oneToManySelect[$table]) && is_array($oneToManySelect[$table]))
{
$newKey = Inflector::singularize($table);
@ -1345,14 +1369,16 @@ class Model extends Object
}
$this->joinedHasMany[] = new NeatArray($this->db->fields($table));
}
if(!empty($newValue))
{
$data = $newValue;
unset($newValue);
}
return $newValue;
}
if(!empty($this->_manyToMany))
/**
* Enter description here...
*
* @param unknown_type $data
* @return unknown
*/
function _findManyToMany(&$data)
{
$datacheck = $data;
$original = $data;
@ -1374,9 +1400,9 @@ class Model extends Object
$tmpSQL = "SELECT * FROM {$table}
JOIN {$joineTable} ON {$joineTable}.{$joinKey1} = '$value2[id]'
AND {$joineTable}.{$JoinKey2} = {$table} .id";
$manyToManySelect[$table] = $this->db->all($tmpSQL);
}
if( !empty($manyToManySelect[$table]) && is_array($manyToManySelect[$table]))
{
$newKey = Inflector::singularize($table);
@ -1417,12 +1443,7 @@ class Model extends Object
}
$this->joinedHasAndBelongs[] = new NeatArray($this->db->fields($table));
}
if(!empty($newValue))
{
$data = $newValue;
}
}
return $data;
return $newValue;
}
/**
@ -1601,6 +1622,11 @@ class Model extends Object
return false;
}
/**
* Enter description here...
*
* @return unknown
*/
function getDisplayField()
{
// $displayField defaults to 'name'
@ -1618,19 +1644,33 @@ class Model extends Object
return $dispField;
}
/**
* Enter description here...
*
* @return unknown
*/
function getLastInsertID()
{
return $this->db->lastInsertId($this->table, 'id');
}
function _throwMissingTable($table_name)
/**
* Enter description here...
*
* @param unknown_type $tableName
*/
function _throwMissingTable($tableName)
{
$error = new AppController();
$error->missingTable = get_class($this);
call_user_func_array(array(&$error, 'missingTable'), $table_name);
call_user_func_array(array(&$error, 'missingTable'), $tableName);
exit;
}
/**
* Enter description here...
*
*/
function _throwMissingConnection()
{
$error = new AppController();

View file

@ -114,7 +114,7 @@ class Scaffold extends Object {
$this->scaffoldTitle = Inflector::humanize($this->modelKey);
$this->controllerClass->layout = 'scaffold';
$this->controllerClass->pageTitle = $this->scaffoldTitle;
$this->controllerClass->contructClasses();
$this->controllerClass->constructClasses();
}
/**
@ -250,7 +250,7 @@ class Scaffold extends Object {
{
// clean up the date fields
$objModel = $this->controllerClass->models[$this->modelKey];
foreach( $objModel->_table_info as $table )
foreach( $objModel->_tableInfo as $table )
{
foreach ($table as $field)
{