diff --git a/cake/scripts/bake.php b/cake/scripts/bake.php index b174e2c94..3bc2a1e46 100644 --- a/cake/scripts/bake.php +++ b/cake/scripts/bake.php @@ -68,36 +68,54 @@ } } - if (strlen($app) && $app[0] == DS) { - $cnt = substr_count($root, DS); - $app = str_repeat('..' . DS, $cnt) . $app; - } - define ('ROOT', $root.DS); - define ('APP_DIR', $app); - define ('DEBUG', 1);; - define('CAKE_CORE_INCLUDE_PATH', ROOT); + if($projectPath) $app = $projectPath; + $shortPath = str_replace($root, '', $app); + $shortPath = str_replace('../', '', $shortPath); + $shortPath = str_replace('//', '/', $shortPath); + + $appDir = basename($shortPath); + $rootDir = str_replace($appDir, '', $shortPath); + define ('ROOT', $rootDir); + define ('APP_DIR', $appDir); + define ('DEBUG', 1);; + define('CAKE_CORE_INCLUDE_PATH', $root); + if(function_exists('ini_set')) { ini_set('include_path',ini_get('include_path'). PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.DS. - PATH_SEPARATOR.CORE_PATH.DS. - PATH_SEPARATOR.ROOT.DS.APP_DIR.DS. - PATH_SEPARATOR.APP_DIR.DS. - PATH_SEPARATOR.APP_PATH); + PATH_SEPARATOR.ROOT.DS.APP_DIR.DS); define('APP_PATH', null); define('CORE_PATH', null); } else { define('APP_PATH', ROOT . DS . APP_DIR . DS); define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS); } + /** + * Tag template for a div with a class attribute. + */ + define('TAG_DIV', '
%s
'); + /** + * Tag template for a paragraph with a class attribute. + */ + define('TAG_P_CLASS', '

%s

'); + /** + * Tag template for a label with a for attribute. + */ + define('TAG_LABEL', ''); + /** + * Tag template for a fieldset with a legend tag inside. + */ + define('TAG_FIELDSET', '
%s%s'); + - require_once (ROOT.'cake'.DS.'basics.php'); - require_once (ROOT.'cake'.DS.'config'.DS.'paths.php'); - require_once (ROOT.'cake'.DS.'dispatcher.php'); - require_once (ROOT.'cake'.DS.'scripts'.DS.'templates'.DS.'skel'.DS.'config'.DS.'core.php'); + require_once (CORE_PATH.'cake'.DS.'basics.php'); + require_once (CORE_PATH.'cake'.DS.'config'.DS.'paths.php'); + require_once (CORE_PATH.'cake'.DS.'dispatcher.php'); + require_once (CORE_PATH.'cake'.DS.'scripts'.DS.'templates'.DS.'skel'.DS.'config'.DS.'core.php'); uses ('inflector', 'model'.DS.'model'); - require_once (ROOT.'cake'.DS.'app_model.php'); - require_once (ROOT.'cake'.DS.'app_controller.php'); + require_once (CORE_PATH.'cake'.DS.'app_model.php'); + require_once (CORE_PATH.'cake'.DS.'app_controller.php'); uses ('neat_array', 'model'.DS.'connection_manager', 'controller'.DS.'controller', 'session', 'configure', 'security', DS.'controller'.DS.'scaffold'); @@ -144,7 +162,7 @@ class Bake { * * @var string */ - var $lowCtrl = null; + var $controllerName = null; /** * If true, Bake will ask for permission to perform actions. * @@ -217,8 +235,40 @@ class Bake { $this->hr(); $this->stdout('Database Configuration Bake:'); $this->hr(); - $driver = 'mysql'; - $connect = 'mysql_connect'; + + $driver = ''; + + while ($driver == '') { + $driver = $this->getInput('What database driver would you like to use?', array('mysql','mysqli','mssql','sqlite','postgres', 'odbc'), 'mysql'); + if ($driver == '') { + $this->stdout('The database driver supplied was empty. Please supply a database driver.'); + } + } + + switch($driver) { + case 'mysql': + $connect = 'mysql_pconnect'; + break; + case 'mysqli': + $connect = 'mysqli_connect'; + break; + case 'mssql': + $connect = 'mssql_pconnect'; + break; + case 'sqlite': + $connect = 'sqlite_popen'; + break; + case 'postgres': + $connect = 'pg_pconnect'; + break; + case 'odbc': + $connect = 'odbc_pconnect'; + break; + default: + $this->stdout('The connection parameter could not be set.'); + break; + } + $host = ''; while ($host == '') { @@ -258,20 +308,30 @@ class Bake { $this->stdout('The database name you supplied was empty. Please try again.'); } } + + $prefix = ''; + + while ($prefix == '') { + $prefix = $this->getInput('Enter a table prefix?', null, 'n'); + } $this->stdout(''); $this->hr(); $this->stdout('The following database configuration will be created:'); $this->hr(); - $this->stdout("Host: $host"); - $this->stdout("User: $login"); - $this->stdout("Pass: " . str_repeat('*', strlen($password))); - $this->stdout("Database: $database"); + $this->stdout("Driver: $driver"); + $this->stdout("Connection: $connect"); + $this->stdout("Host: $host"); + $this->stdout("User: $login"); + $this->stdout("Pass: " . str_repeat('*', strlen($password))); + $this->stdout("Database: $database"); + if($prefix != '') + $this->stdout("Table prefix: $prefix"); $this->hr(); $looksGood = $this->getInput('Look okay?', array('y', 'n'), 'y'); if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') { - $this->bakeDbConfig($host, $login, $password, $database); + $this->bakeDbConfig($driver, $connect, $host, $login, $password, $database, $prefix); } else { $this->stdout('Bake Aborted.'); } @@ -292,7 +352,6 @@ class Bake { { $dbConnection = $this->getInput('Please provide the name of the connection you wish to use.'); }*/ - $modelName = ''; $db =& ConnectionManager::getDataSource($dbConnection); $usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix']; if ($usePrefix) { @@ -306,42 +365,48 @@ class Bake { $tables = $db->listSources(); } - $inflect = & new Inflector(); $this->stdout('Possible models based on your current database:'); for ($i = 0; $i < count($tables); $i++) { - $this->stdout($i + 1 . ". " . $inflect->classify($tables[$i])); + $this->stdout($i + 1 . ". " . $this->__modelName($tables[$i])); } + + $enteredModel = ''; + + while ($enteredModel == '') { + $enteredModel = $this->getInput('Enter a number from the list above, or type in the name of another model.'); - while ($modelName == '') { - $modelName = $this->getInput('Enter a number from the list above, or type in the name of another model.'); - - if ($modelName == '' || intval($modelName) > $i) { + if ($enteredModel == '' || intval($enteredModel) > $i) { $this->stdout('Error:'); $this->stdout("The model name you supplied was empty, or the number \nyou selected was not an option. Please try again."); - $modelName = ''; + $enteredModel = ''; } } - if (intval($modelName) > 0 && intval($modelName) <= $i ) { - $modelClassName = $inflect->classify($tables[$modelName - 1]); - $modelTableName = $tables[intval($modelName) - 1]; + if (intval($enteredModel) > 0 && intval($enteredModel) <= $i ) { + $currentModelName = $this->__modelName($tables[intval($enteredModel) - 1]); } else { - $modelClassName = $inflect->camelize($modelName); - $this->stdout("\nGiven your model named '$modelClassName', Cake would expect a database table named '" . $inflect->pluralize($modelName) . "'."); - $tableIsGood = $this->getInput('Is this correct?', array('y','n'), 'y'); - - if (strtolower($tableIsGood) == 'n' || strtolower($tableIsGood) == 'no') { - $modelTableName = $this->getInput('What is the name of the table (enter "null" to use NO table)?'); - } + $currentModelName = $this->__modelName($enteredModel); } + + $currentTableName = Inflector::tableize($currentModelName); + + $this->stdout("\nGiven your model named '$currentModelName', Cake would expect a database table named '" . $currentTableName . "'."); + $tableIsGood = $this->getInput('Is this correct?', array('y','n'), 'y'); + + if (strtolower($tableIsGood) == 'n' || strtolower($tableIsGood) == 'no') { + $table = $this->getInput('What is the name of the table (enter "null" to use NO table)?'); + } + $wannaDoValidation = $this->getInput('Would you like to supply validation criteria for the fields in your model?', array('y','n'), 'y'); - $validate = array(); - $tempModel = new Model(false, $modelTableName); + + $tempModel = new Model(false, $currentTableName); $modelFields = $db->describe($tempModel); + + $validate = array(); - if (array_search($modelTableName, $tables) !== false && (strtolower($wannaDoValidation) == 'y' || strtolower($wannaDoValidation) == 'yes')) { + if (array_search($currentModelName, $tables) !== false && (strtolower($wannaDoValidation) == 'y' || strtolower($wannaDoValidation) == 'yes')) { foreach($modelFields as $field) { $this->stdout(''); $prompt .= 'Name: ' . $field['name'] . "\n"; @@ -379,12 +444,11 @@ class Bake { break; default: $validate[$field['name']] = $validation; - break; + break; } } } - $modelTableName == null ? $modelTableName = $inflect->pluralize($modelName) : $modelTableName = $modelTableName; $wannaDoAssoc = $this->getInput('Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)?', array('y','n'), 'y'); if((strtolower($wannaDoAssoc) == 'y' || strtolower($wannaDoAssoc) == 'yes')) { @@ -392,32 +456,31 @@ class Bake { //Look for belongsTo foreach($modelFields as $field) { $offset = strpos($field['name'], '_id'); - if($offset !== false) { - $belongsToClasses[] = $inflect->camelize(substr($field['name'], 0, $offset)); + $belongsToClasses[] = $this->__modelNameFromKey($field['name']); } } //Look for hasOne and hasMany and hasAndBelongsToMany - foreach($tables as $table) { - $tempModelOthers = new Model(false, $table); - $modelFieldsTemp = $db->describe($tempModelOthers); + foreach($tables as $otherTable) { + $tempOtherModel = new Model(false, $otherTable); + $modelFieldsTemp = $db->describe($tempOtherModel); foreach($modelFieldsTemp as $field) { - if($field['name'] == $inflect->singularize($modelTableName).'_id') { - $hasOneClasses[] = $inflect->classify($table); - $hasManyClasses[] = $inflect->classify($table); + if($field['name'] == $this->__modelKey($currentModelName)) { + $hasOneClasses[] = $this->__modelName($otherTable); + $hasManyClasses[] = $this->__modelName($otherTable); } } - $offset = strpos($table, $modelTableName . '_'); - + $offset = strpos($otherTable, $currentTableName . '_'); if($offset !== false) { - $offset = strlen($modelTableName . '_'); - $hasAndBelongsToManyClasses[] = $inflect->classify(substr($table, $offset)); + $offset = strlen($currentTableName . '_'); + echo $this->__modelName(substr($otherTable, $offset)); + $hasAndBelongsToManyClasses[] = $this->__modelName(substr($otherTable, $offset)); } - $offset = strpos($table, '_' . $modelTableName); - + $offset = strpos($otherTable, '_' . $currentTableName); if ($offset !== false) { - $hasAndBelongsToManyClasses[] = $inflect->classify(substr($table, 0, $offset)); + echo $this->__modelName(substr($otherTable, 0, $offset)); + $hasAndBelongsToManyClasses[] = $this->__modelName(substr($otherTable, 0, $offset)); } } @@ -432,7 +495,7 @@ class Bake { if(count($belongsToClasses)) { for($i = 0; $i < count($belongsToClasses); $i++) { - $response = $this->getInput("$modelClassName belongsTo {$belongsToClasses[$i]}?", array('y','n'), 'y'); + $response = $this->getInput("$currentModelName belongsTo {$belongsToClasses[$i]}?", array('y','n'), 'y'); if($response == 'y') { $modelAssociations['belongsTo'][] = $belongsToClasses[$i]; @@ -442,7 +505,7 @@ class Bake { if(count($hasOneClasses)) { for($i = 0; $i < count($hasOneClasses); $i++) { - $response = $this->getInput("$modelClassName hasOne {$hasOneClasses[$i]}?", array('y','n'), 'y'); + $response = $this->getInput("$currentModelName hasOne {$hasOneClasses[$i]}?", array('y','n'), 'y'); if($response == 'y') { $modelAssociations['hasOne'][] = $hasOneClasses[$i]; @@ -452,7 +515,7 @@ class Bake { if(count($hasManyClasses)) { for($i = 0; $i < count($hasManyClasses); $i++) { - $response = $this->getInput("$modelClassName hasMany {$hasManyClasses[$i]}?", array('y','n'), 'y'); + $response = $this->getInput("$currentModelName hasMany {$hasManyClasses[$i]}?", array('y','n'), 'y'); if($response == 'y') { $modelAssociations['hasMany'][] = $hasManyClasses[$i]; @@ -462,7 +525,7 @@ class Bake { if(count($hasAndBelongsToManyClasses)) { for($i = 0; $i < count($hasAndBelongsToManyClasses); $i++) { - $response = $this->getInput("$modelClassName hasAndBelongsToMany {$hasAndBelongsToManyClasses[$i]}?", array('y','n'), 'y'); + $response = $this->getInput("$currentModelName hasAndBelongsToMany {$hasAndBelongsToManyClasses[$i]}?", array('y','n'), 'y'); if($response == 'y') { $modelAssociations['hasAndBelongsToMany'][] = $hasAndBelongsToManyClasses[$i]; @@ -491,7 +554,7 @@ class Bake { } $assocClassName = $this->getInput('Classname of associated Model?'); $modelAssociations[$assocs[$assocType]][] = $assocClassName; - $this->stdout("Association '$modelClassName {$assocs[$assocType]} $assocClassName' defined."); + $this->stdout("Association '$currentModelName {$assocs[$assocType]} $assocClassName' defined."); $wannaDoMoreAssoc = $this->getInput('Define another association?', array('y','n'), 'y'); } } @@ -499,9 +562,9 @@ class Bake { $this->hr(); $this->stdout('The following model will be created:'); $this->hr(); - $this->stdout("Model Name: $modelClassName"); + $this->stdout("Model Name: $currentModelName"); $this->stdout("DB Connection: " . ($usingDefault ? 'default' : $dbConnection)); - $this->stdout("Model Table: " . $modelTableName); + $this->stdout("Model Table: " . $currentTableName); $this->stdout("Validation: " . print_r($validate, true)); if(count($belongsToClasses) || count($hasOneClasses) || count($hasManyClasses) || count($hasAndBelongsToManyClasses)) { @@ -509,25 +572,25 @@ class Bake { if(count($modelAssociations['belongsTo'])) { for($i = 0; $i < count($modelAssociations['belongsTo']); $i++) { - $this->stdout(" $modelClassName belongsTo {$modelAssociations['belongsTo'][$i]}"); + $this->stdout(" $currentModelName belongsTo {$modelAssociations['belongsTo'][$i]}"); } } if(count($modelAssociations['hasOne'])) { for($i = 0; $i < count($modelAssociations['hasOne']); $i++) { - $this->stdout(" $modelClassName hasOne {$modelAssociations['hasOne'][$i]}"); + $this->stdout(" $currentModelName hasOne {$modelAssociations['hasOne'][$i]}"); } } if(count($modelAssociations['hasMany'])) { for($i = 0; $i < count($modelAssociations['hasMany']); $i++) { - $this->stdout(" $modelClassName hasMany {$modelAssociations['hasMany'][$i]}"); + $this->stdout(" $currentModelName hasMany {$modelAssociations['hasMany'][$i]}"); } } if(count($modelAssociations['hasAndBelongsToMany'])) { for($i = 0; $i < count($modelAssociations['hasAndBelongsToMany']); $i++) { - $this->stdout(" $modelClassName hasAndBelongsToMany {$modelAssociations['hasAndBelongsToMany'][$i]}"); + $this->stdout(" $currentModelName hasAndBelongsToMany {$modelAssociations['hasAndBelongsToMany'][$i]}"); } } } @@ -535,16 +598,16 @@ class Bake { $looksGood = $this->getInput('Look okay?', array('y','n'), 'y'); if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') { - if ($modelTableName == $inflect->tableize($modelClassName)) { + if ($currentTableName == Inflector::tableize($currentModelName)) { // set it to null... // putting $useTable in the model // is unnecessary. $modelTableName = null; } - $this->bakeModel($modelClassName, $dbConnection, $modelTableName, $validate, $modelAssociations); + $this->bakeModel($currentModelName, $dbConnection, $currentTableName, $validate, $modelAssociations); if ($this->doUnitTest()) { - $this->bakeUnitTest('model', $modelClassName); + $this->bakeUnitTest('model', $currentModelName); } } else { $this->stdout('Bake Aborted.'); @@ -561,9 +624,8 @@ class Bake { $uses = array(); $wannaUseSession = 'y'; $wannaDoScaffold = 'y'; + $controllerName = ''; - $inflect = & new Inflector(); - while ($controllerName == '') { $controllerName = $this->getInput('Controller Name? (plural)'); @@ -571,17 +633,30 @@ class Bake { $this->stdout('The controller name you supplied was empty. Please try again.'); } } - $controllerName = $inflect->underscore($controllerName); - $this->lowCtrl = $controllerName; + $this->controllerPath = $this->__controllerFn($controllerName); + $this->controllerName = $this->__controllerName($controllerName); + $doItInteractive = $this->getInput("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite {$controllerClassName} views if it exist.", array('y','n'), 'y'); if (strtolower($doItInteractive) == 'y' || strtolower($doItInteractive) == 'yes') { $this->interactive = true; $wannaDoScaffold = $this->getInput("Would you like to create some scaffolded views (index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller and model classes (including associated models).", array('y','n'), 'n'); } - + + $admin = null; if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoScaffold) == 'yes') { - $file = CONTROLLERS . $controllerName . '_controller.php'; + $wannaDoAdmin = $this->getInput("Would you like to create the views for admin routing?", array('y','n'), 'n'); + } + + if ((strtolower($wannaDoAdmin) == 'y' || strtolower($wannaDoAdmin) == 'yes')) { + if(defined('CAKE_ADMIN')) { + $admin = CAKE_ADMIN.'_'; + } else { + $this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.'); + } + } + if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoScaffold) == 'yes') { + $file = CONTROLLERS . $this->controllerPath . '_controller.php'; if(!file_exists($file)) { $shortPath = str_replace(ROOT, null, $file); @@ -592,190 +667,198 @@ class Bake { $this->stdout(''); die(); } else { - require_once(CONTROLLERS . $controllerName . '_controller.php'); - $controller = $inflect->camelize($controllerName . '_controller'); - $temp = new $controller(); - - if(!in_array('Form', $temp->helpers)) { - $temp->helpers[] = 'Form'; + loadController($this->controllerName); + $controllerClassName = $this->controllerName.'Controller'; + $controllerObj = & new $controllerClassName(); + + if(!in_array('Html', $controllerObj->helpers)) { + $controllerObj->helpers[] = 'Html'; } + if(!in_array('Form', $controllerObj->helpers)) { + $controllerObj->helpers[] = 'Form'; + } + loadModels(); - $temp->constructClasses(); - $fieldNames = $temp->generateFieldNames(null, false); - uses('view'.DS.'helpers'.DS.'html', 'view'.DS.'helpers'.DS.'form'); - $this->Html = new HtmlHelper(); - $this->Html->tags = $this->Html->loadConfig(); + $controllerObj->constructClasses(); + $currentModelName = $controllerObj->modelClass; + $modelKey = Inflector::underscore($currentModelName); + $modelObj =& ClassRegistry::getObject($modelKey); + $singularName = $this->__singularName($currentModelName); + $singularHumanName = $this->__singularHumanName($modelObj->name); + $pluralHumanName = $this->__pluralHumanName($this->controllerName); + + $fieldNames = $controllerObj->generateFieldNames(null, false); //-------------------------[INDEX]-------------------------// - if(!empty($temp->{$temp->modelClass}->alias)) { - foreach ($temp->{$temp->modelClass}->alias as $key => $value) { + if(!empty($modelObj->alias)) { + foreach ($modelObj->alias as $key => $value) { $alias[] = $key; } } - $indexView .= "

List " . ucwords($inflect->humanize($inflect->pluralize($temp->modelKey))) . "

\n\n"; + $indexView .= "

List " . $pluralHumanName . "

\n\n"; $indexView .= "\n"; $indexView .= "\n"; - + foreach ($fieldNames as $fieldName) { $indexView .= "\t\n"; } $indexView .= "\t\n"; $indexView .= "\n"; - $indexView .= "lowCtrl} as \$".$inflect->singularize($this->lowCtrl)."): ?>\n"; + $indexView .= "controllerPath} as \${$singularName}): ?>\n"; $indexView .= "\n"; $count = 0; foreach($fieldNames as $field => $value) { if(isset($value['foreignKey'])) { - $otherModelKey = $inflect->underscore($value['modelKey']); + $otherModelKey = Inflector::underscore($value['modelKey']); $otherControllerName = $value['controller']; - $otherModelObject =& ClassRegistry::getObject($otherModelKey); - - if(is_object($otherModelObject)) { - $indexView .= "\t\n"; + $otherModelObj =& ClassRegistry::getObject($otherModelKey); + if(is_object($otherModelObj)) { + $indexView .= "\t\n"; } else { - $indexView .= "\t\n"; + $indexView .= "\t\n"; } $count++; } else { - $indexView .= "\t\n"; + $indexView .= "\t\n"; } } - $id = $temp->{$temp->modelClass}->primaryKey; - $indexView .= "\t\n"; $indexView .= "\n"; $indexView .= "\n"; $indexView .= "
".$fieldName['prompt']."Actions
link(\$".$inflect->singularize($this->lowCtrl)."['" . $alias[$count] ."']['" . $otherModelObject->getDisplayField() ."'], '/" . $inflect->pluralize($inflect->underscore(strtolower($alias[$count]))) ."/view/' .\$".$inflect->singularize($this->lowCtrl)."['{$alias[$count]}']['{$otherModelObject->primaryKey}']);?>link(\$".$singularName."['" . $alias[$count] ."']['" . $otherModelObj->getDisplayField() ."'], '/" . $this->__controllerFn($otherControllerName)."/view/' .\$".$singularName."['{$alias[$count]}']['{$otherModelObj->primaryKey}']);?>singularize($this->lowCtrl)."['" . $alias[$count] ."']['" . $field ."'] ?>name}']['{$field}']; ?>singularize($this->lowCtrl)."['{$temp->modelClass}']['{$field}'] ?>name}']['{$field}']; ?>\n"; - $indexView .= "\t\tlink('View','/$temp->viewPath/view/' . \$".$inflect->singularize($this->lowCtrl)."['{$temp->modelClass}']['$id'])?>\n"; - $indexView .= "\t\tlink('Edit','/$temp->viewPath/edit/' . \$".$inflect->singularize($this->lowCtrl)."['{$temp->modelClass}']['$id'])?>\n"; - $indexView .= "\t\tlink('Delete','/$temp->viewPath/delete/' . \$".$inflect->singularize($this->lowCtrl)."['{$temp->modelClass}']['$id'], null, 'Are you sure you want to delete: id ' . \$".$inflect->singularize($this->lowCtrl)."['{$temp->modelClass}']['$id'])?>\n"; + $indexView .= "\t\n"; + $indexView .= "\t\tlink('View','/{$this->controllerPath}/view/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])?>\n"; + $indexView .= "\t\tlink('Edit','/{$this->controllerPath}/edit/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])?>\n"; + $indexView .= "\t\tlink('Delete','/{$this->controllerPath}/delete/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'], null, 'Are you sure you want to delete: id ' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])?>\n"; $indexView .= "\t
\n\n"; $indexView .= "\n"; //-------------------------[VIEW]-------------------------// - $modelName = $temp->modelClass; - $modelKey = $inflect->underscore($modelName); - $objModel =& ClassRegistry::getObject($modelKey); - $viewView .= "

View " . ucwords($inflect->humanize($inflect->pluralize($temp->modelKey))) . "

\n\n"; + $viewView .= "

View " . $singularHumanName . "

\n\n"; $count = 0; $viewView .= "
\n"; foreach($fieldNames as $field => $value) { $viewView .= "\t
" . $value['prompt'] . "
\n"; - if(isset($value['foreignKey'])) { - $otherModelObject =& ClassRegistry::getObject($inflect->underscore($objModel->tableToModel[$value['table']])); - $displayField = $otherModelObject->getDisplayField(); - $viewView .= "\t
 link(\$".$inflect->singularize($this->lowCtrl)."['{$alias[$count]}']['{$displayField}'], '/" . $inflect->underscore($value['controller']) . "/view/' .\$".$inflect->singularize($this->lowCtrl)."['{$objModel->tableToModel[$objModel->table]}']['{$field}'])?>
\n"; + $otherControllerName = $value['controller']; + $otherModelKey = Inflector::underscore($value['modelKey']); + $otherModelObj =& ClassRegistry::getObject($otherModelKey); + $displayField = $otherModelObj->getDisplayField(); + $viewView .= "\t
 link(\$".$singularName."['{$alias[$count]}']['{$displayField}'], '/" . $this->__controllerFn($value['controller']) . "/view/' .\$".$singularName."['{$alias[$count]}']['{$otherModelObj->primaryKey}'])?>
\n"; $count++; } else { - $viewView .= "\t
 singularize($this->lowCtrl)."['{$objModel->tableToModel[$objModel->table]}']['{$field}']?>
\n"; + $viewView .= "\t
 name}']['{$field}']?>
\n"; } } $viewView .= "
\n"; + $viewView .= "\n\n"; - foreach ($objModel->hasOne as $association => $relation) { - $model = $relation['className']; - $otherModelName = $objModel->tableToModel[$objModel->{$model}->table]; - $controller = $inflect->pluralize($model); + foreach ($modelObj->hasOne as $associationName => $relation) { + $otherModelName = $this->__modelName($relation['className']); + $otherControllerName = $this->__controllerName($otherModelName); + $otherControllerPath = $this->__controllerFn($otherModelName); + $otherSingularName = $this->__singularName($associationName); + $new = true; - $viewView .= "