From 38076557aae8c13fb701fcc8964b115c198db74e Mon Sep 17 00:00:00 2001 From: phpnut Date: Mon, 24 Oct 2005 03:44:54 +0000 Subject: [PATCH] [1183] 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 --- cake/basics.php | 8 +++---- cake/dispatcher.php | 3 +-- cake/libs/controller/controller.php | 36 +++++++++++------------------ cake/libs/model/model.php | 5 ---- cake/libs/new_inflector.php | 2 +- 5 files changed, 20 insertions(+), 34 deletions(-) diff --git a/cake/basics.php b/cake/basics.php index 548af2dc0..60eb45bc6 100644 --- a/cake/basics.php +++ b/cake/basics.php @@ -98,13 +98,13 @@ function loadControllers () */ 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 { diff --git a/cake/dispatcher.php b/cake/dispatcher.php index 2c77fa81a..341dfe2aa 100644 --- a/cake/dispatcher.php +++ b/cake/dispatcher.php @@ -95,7 +95,7 @@ class Dispatcher extends Object $ctrlName = Inflector::camelize($params['controller']); $ctrlClass = $ctrlName.'Controller'; - if (!loadController($ctrlName) || !class_exists($ctrlClass)) + if (!loadController($params['controller']) || !class_exists($ctrlClass)) { if(preg_match('/([\\.]+)/',$ctrlName)) { @@ -148,7 +148,6 @@ class Dispatcher extends Object $controller->action = $params['action']; $controller->data = empty($params['data'])? null: $params['data']; $controller->passed_args = empty($params['pass'])? null: $params['pass']; - $controller->viewpath = Inflector::underscore($ctrlName); $controller->autoLayout = !$params['bare']; $controller->autoRender = !$params['render']; diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index af777bc3a..ae38e4806 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -200,7 +200,9 @@ class Controller extends Object } $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); $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->modelNames[] = $modelClass; + $this->{$this->modelClass} =& new $this->modelClass($id); + $this->modelNames[] = $this->modelClass; } elseif ($this->uses) { @@ -264,10 +263,9 @@ class Controller extends Object $uses = is_array($this->uses)? $this->uses: array($this->uses); - foreach ($uses as $modelName) + foreach ($uses as $modelClass) { - $modelClass = ucfirst(strtolower($modelName)); - $modelKey = strtolower(Inflector::underscore($modelClass)); + $modelKey = Inflector::underscore($modelClass); if (class_exists($modelClass)) { @@ -367,10 +365,9 @@ class Controller extends Object { foreach ($this->modelNames as $model) { - $key = Inflector::underscore($model); 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 ) { - // Initialize the list array $fieldNames = array(); - - // figure out what model and table we are working with - $model = Inflector::singularize($this->name); - $modelKey = Inflector::underscore($model); + + $model = $this->modelClass; + $modelKey = $this->modelKey; $table = $this->{$model}->table; - - // get all of the column names. $classRegistry =& ClassRegistry::getInstance(); $objRegistryModel = $classRegistry->getObject($modelKey); - foreach ($objRegistryModel->_tableInfo as $tables) { @@ -799,7 +791,7 @@ class Controller extends Object { list($tableName) = $relation; - $otherModelName = Inflector::singularize($tableName); + $otherModelName = Inflector::underscore($tableName); $otherModel = new $otherModelName(); if( $doCreateOptions ) @@ -808,7 +800,7 @@ class Controller extends Object $fieldNames[$tableName]['model'] = $tableName; $fieldNames[$tableName]['prompt'] = "Related ".Inflector::humanize($tableName); $fieldNames[$tableName]['type'] = "selectMultiple"; - $fieldNames[$tableName]['tagName'] = $otherModelName.'/'.$tableName; + $fieldNames[$tableName]['tagName'] = $otherModelName.'/'.Inflector::underscore($tableName); foreach( $otherModel->findAll() as $pass ) { diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index a0b7862bd..47a214253 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -276,7 +276,6 @@ class Model extends Object $association = explode(',', $this->belongsTo); foreach ($association as $className) { - $className = Inflector::singularize($className); $this->_constructAssociatedModels($className , 'Belongs'); $this->linkAssociation('Belongs', $className, $this->id); } @@ -303,7 +302,6 @@ class Model extends Object $association = explode(',', $this->hasOne); foreach ($association as $className) { - $className = Inflector::singularize($className); $this->_constructAssociatedModels($className , 'One'); $this->linkAssociation('One', $className, $this->id); } @@ -330,7 +328,6 @@ class Model extends Object $association = explode(',', $this->hasMany); foreach ($association as $className) { - $className = Inflector::singularize($className); $this->_constructAssociatedModels($className , 'Many'); $this->linkAssociation('Many', $className, $this->id); } @@ -357,7 +354,6 @@ class Model extends Object $association = explode(',', $this->hasAndBelongsToMany); foreach ($association as $className) { - $className = Inflector::singularize($className); $this->_constructAssociatedModels($className , 'ManyTo'); $this->linkAssociation('ManyTo', $className, $this->id); } @@ -385,7 +381,6 @@ class Model extends Object if ($classCreated === false) { - $className = Inflector::singularize($className); $this->_constructAssociatedModels($className , $type); $classCreated = true; } diff --git a/cake/libs/new_inflector.php b/cake/libs/new_inflector.php index ecffd12df..8955120c2 100644 --- a/cake/libs/new_inflector.php +++ b/cake/libs/new_inflector.php @@ -110,7 +110,7 @@ class Inflector { $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))));