Author: phpnut
Date: 10:42:06 PM, Sunday, October 23, 2005
Message:
Fixed errors created with change I have been making.
Controller::generateFields(); was not setting the tagName properly.

[1182]
Author: phpnut
Date: 10:13:33 PM, Sunday, October 23, 2005
Message:
Removing the need to set hasMany and hasAndBelongsToMany to plural.
All associations should be created as CamelCase associations now.

[1181]
Author: phpnut
Date: 9:38:50 PM, Sunday, October 23, 2005
Message:
Forgot dispatcher.php in last commit

[1180]
Author: phpnut
Date: 9:37:06 PM, Sunday, October 23, 2005
Message:
refactoring and removing unneeded calls to Inflector


git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1184 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-10-24 03:44:54 +00:00
parent 68b194965e
commit 38076557aa
5 changed files with 20 additions and 34 deletions

View file

@ -98,13 +98,13 @@ function loadControllers ()
*/ */
function loadController ($name) function loadController ($name)
{ {
if(file_exists(CONTROLLERS.Inflector::underscore($name).'_controller.php')) if(file_exists(CONTROLLERS.$name.'_controller.php'))
{ {
$controller_fn = CONTROLLERS.Inflector::underscore($name).'_controller.php'; $controller_fn = CONTROLLERS.$name.'_controller.php';
} }
elseif(file_exists(LIBS.'controller'.DS.Inflector::underscore($name).'_controller.php')) elseif(file_exists(LIBS.'controller'.DS.$name.'_controller.php'))
{ {
$controller_fn = LIBS.'controller'.DS.Inflector::underscore($name).'_controller.php'; $controller_fn = LIBS.'controller'.DS.$name.'_controller.php';
} }
else else
{ {

View file

@ -95,7 +95,7 @@ class Dispatcher extends Object
$ctrlName = Inflector::camelize($params['controller']); $ctrlName = Inflector::camelize($params['controller']);
$ctrlClass = $ctrlName.'Controller'; $ctrlClass = $ctrlName.'Controller';
if (!loadController($ctrlName) || !class_exists($ctrlClass)) if (!loadController($params['controller']) || !class_exists($ctrlClass))
{ {
if(preg_match('/([\\.]+)/',$ctrlName)) if(preg_match('/([\\.]+)/',$ctrlName))
{ {
@ -148,7 +148,6 @@ class Dispatcher extends Object
$controller->action = $params['action']; $controller->action = $params['action'];
$controller->data = empty($params['data'])? null: $params['data']; $controller->data = empty($params['data'])? null: $params['data'];
$controller->passed_args = empty($params['pass'])? null: $params['pass']; $controller->passed_args = empty($params['pass'])? null: $params['pass'];
$controller->viewpath = Inflector::underscore($ctrlName);
$controller->autoLayout = !$params['bare']; $controller->autoLayout = !$params['bare'];
$controller->autoRender = !$params['render']; $controller->autoRender = !$params['render'];

View file

@ -200,7 +200,9 @@ class Controller extends Object
} }
$this->viewPath = Inflector::underscore($this->name); $this->viewPath = Inflector::underscore($this->name);
parent::__construct(); $this->modelClass = Inflector::singularize($this->name);
$this->modelKey = Inflector::underscore($this->modelClass);
parent::__construct();
} }
/** /**
@ -246,14 +248,11 @@ class Controller extends Object
$dboFactory = DboFactory::getInstance($this->useDbConfig); $dboFactory = DboFactory::getInstance($this->useDbConfig);
$this->db =& $dboFactory; $this->db =& $dboFactory;
$modelClass = Inflector::singularize($this->name);
$modelKey = strtolower(Inflector::underscore($modelClass));
if (class_exists($modelClass) && ($this->uses === false)) if (class_exists($this->modelClass) && ($this->uses === false))
{ {
$this->{$modelClass} =& new $modelClass($id); $this->{$this->modelClass} =& new $this->modelClass($id);
$this->modelNames[] = $modelClass; $this->modelNames[] = $this->modelClass;
} }
elseif ($this->uses) elseif ($this->uses)
{ {
@ -264,10 +263,9 @@ class Controller extends Object
$uses = is_array($this->uses)? $this->uses: array($this->uses); $uses = is_array($this->uses)? $this->uses: array($this->uses);
foreach ($uses as $modelName) foreach ($uses as $modelClass)
{ {
$modelClass = ucfirst(strtolower($modelName)); $modelKey = Inflector::underscore($modelClass);
$modelKey = strtolower(Inflector::underscore($modelClass));
if (class_exists($modelClass)) if (class_exists($modelClass))
{ {
@ -367,10 +365,9 @@ class Controller extends Object
{ {
foreach ($this->modelNames as $model) foreach ($this->modelNames as $model)
{ {
$key = Inflector::underscore($model);
if(!empty($this->{$model}->validationErrors)) if(!empty($this->{$model}->validationErrors))
{ {
$view->validationErrors[$key] =& $this->{$model}->validationErrors; $view->validationErrors[$this->modelKey] =& $this->{$model}->validationErrors;
} }
} }
} }
@ -582,19 +579,14 @@ class Controller extends Object
*/ */
function generateFieldNames( $data = null, $doCreateOptions = true ) function generateFieldNames( $data = null, $doCreateOptions = true )
{ {
// Initialize the list array
$fieldNames = array(); $fieldNames = array();
// figure out what model and table we are working with $model = $this->modelClass;
$model = Inflector::singularize($this->name); $modelKey = $this->modelKey;
$modelKey = Inflector::underscore($model);
$table = $this->{$model}->table; $table = $this->{$model}->table;
// get all of the column names.
$classRegistry =& ClassRegistry::getInstance(); $classRegistry =& ClassRegistry::getInstance();
$objRegistryModel = $classRegistry->getObject($modelKey); $objRegistryModel = $classRegistry->getObject($modelKey);
foreach ($objRegistryModel->_tableInfo as $tables) foreach ($objRegistryModel->_tableInfo as $tables)
{ {
@ -799,7 +791,7 @@ class Controller extends Object
{ {
list($tableName) = $relation; list($tableName) = $relation;
$otherModelName = Inflector::singularize($tableName); $otherModelName = Inflector::underscore($tableName);
$otherModel = new $otherModelName(); $otherModel = new $otherModelName();
if( $doCreateOptions ) if( $doCreateOptions )
@ -808,7 +800,7 @@ class Controller extends Object
$fieldNames[$tableName]['model'] = $tableName; $fieldNames[$tableName]['model'] = $tableName;
$fieldNames[$tableName]['prompt'] = "Related ".Inflector::humanize($tableName); $fieldNames[$tableName]['prompt'] = "Related ".Inflector::humanize($tableName);
$fieldNames[$tableName]['type'] = "selectMultiple"; $fieldNames[$tableName]['type'] = "selectMultiple";
$fieldNames[$tableName]['tagName'] = $otherModelName.'/'.$tableName; $fieldNames[$tableName]['tagName'] = $otherModelName.'/'.Inflector::underscore($tableName);
foreach( $otherModel->findAll() as $pass ) foreach( $otherModel->findAll() as $pass )
{ {

View file

@ -276,7 +276,6 @@ class Model extends Object
$association = explode(',', $this->belongsTo); $association = explode(',', $this->belongsTo);
foreach ($association as $className) foreach ($association as $className)
{ {
$className = Inflector::singularize($className);
$this->_constructAssociatedModels($className , 'Belongs'); $this->_constructAssociatedModels($className , 'Belongs');
$this->linkAssociation('Belongs', $className, $this->id); $this->linkAssociation('Belongs', $className, $this->id);
} }
@ -303,7 +302,6 @@ class Model extends Object
$association = explode(',', $this->hasOne); $association = explode(',', $this->hasOne);
foreach ($association as $className) foreach ($association as $className)
{ {
$className = Inflector::singularize($className);
$this->_constructAssociatedModels($className , 'One'); $this->_constructAssociatedModels($className , 'One');
$this->linkAssociation('One', $className, $this->id); $this->linkAssociation('One', $className, $this->id);
} }
@ -330,7 +328,6 @@ class Model extends Object
$association = explode(',', $this->hasMany); $association = explode(',', $this->hasMany);
foreach ($association as $className) foreach ($association as $className)
{ {
$className = Inflector::singularize($className);
$this->_constructAssociatedModels($className , 'Many'); $this->_constructAssociatedModels($className , 'Many');
$this->linkAssociation('Many', $className, $this->id); $this->linkAssociation('Many', $className, $this->id);
} }
@ -357,7 +354,6 @@ class Model extends Object
$association = explode(',', $this->hasAndBelongsToMany); $association = explode(',', $this->hasAndBelongsToMany);
foreach ($association as $className) foreach ($association as $className)
{ {
$className = Inflector::singularize($className);
$this->_constructAssociatedModels($className , 'ManyTo'); $this->_constructAssociatedModels($className , 'ManyTo');
$this->linkAssociation('ManyTo', $className, $this->id); $this->linkAssociation('ManyTo', $className, $this->id);
} }
@ -385,7 +381,6 @@ class Model extends Object
if ($classCreated === false) if ($classCreated === false)
{ {
$className = Inflector::singularize($className);
$this->_constructAssociatedModels($className , $type); $this->_constructAssociatedModels($className , $type);
$classCreated = true; $classCreated = true;
} }

View file

@ -110,7 +110,7 @@ class Inflector
{ {
$inflec =& Inflector::getInstance(); $inflec =& Inflector::getInstance();
require_once('config/nouns.php'); require_once(CAKE.'config'.DS.'nouns.php');
$regexPluralUninflected = $inflec->_enclose(join( '|', array_values(array_merge($pluralUninflected,$pluralUninflecteds)))); $regexPluralUninflected = $inflec->_enclose(join( '|', array_values(array_merge($pluralUninflected,$pluralUninflecteds))));