diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index f63188312..171427e0d 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -53,27 +53,7 @@ class ControllerTask extends Shell { $wannaUseScaffold = 'n'; $wannaDoScaffolding = 'y'; - $useDbConfig = 'default'; - $this->__doList($useDbConfig, 'Controllers'); - - $enteredController = ''; - - while ($enteredController == '') { - $enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.'); - - if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) { - $this->out('Error:'); - $this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again."); - $enteredController = ''; - } - } - - if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) { - $controllerName = $this->_controllerNames[intval($enteredController) - 1]; - } else { - $controllerName = Inflector::camelize($enteredController); - } - + $controllerName = $this->__getControllerName(); $controllerPath = low(Inflector::underscore($controllerName)); $doItInteractive = $this->in("Would you like bake to build your controller interactively?\nWarning: Choosing no will overwrite {$controllerName} controller if it exist.", array('y','n'), 'y'); @@ -493,5 +473,35 @@ class ControllerTask extends Shell { $this->_controllerNames[] = $this->_controllerName($this->_modelName($tables[$i])); $this->out($i + 1 . ". " . $this->_controllerNames[$i]); } - } + } + +/** + * Forces the user to specify the controller he wants to bake, and returns the selected controller name. + * + * @return the controller name + */ + function __getControllerName() { + $useDbConfig = 'default'; + $this->__doList($useDbConfig, 'Controllers'); + + $enteredController = ''; + + while ($enteredController == '') { + $enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.'); + + if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) { + $this->out('Error:'); + $this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again."); + $enteredController = ''; + } + } + + if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) { + $controllerName = $this->_controllerNames[intval($enteredController) - 1]; + } else { + $controllerName = Inflector::camelize($enteredController); + } + + return $controllerName; + } } \ No newline at end of file diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index 319a9b10d..cd45503c2 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -57,27 +57,8 @@ class ModelTask extends Shell { $useDbConfig = $this->in('Please provide the name of the connection you wish to use.'); }*/ $useDbConfig = 'default'; - $this->__doList($useDbConfig); - - - $enteredModel = ''; - - while ($enteredModel == '') { - $enteredModel = $this->in('Enter a number from the list above, or type in the name of another model.'); - - if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) { - $this->out('Error:'); - $this->out("The model name you supplied was empty, or the number \nyou selected was not an option. Please try again."); - $enteredModel = ''; - } - } - - if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) { - $currentModelName = $this->_modelNames[intval($enteredModel) - 1]; - } else { - $currentModelName = $enteredModel; - } - + $currentModelName = $this->__getModelName($useDbConfig); + $db =& ConnectionManager::getDataSource($useDbConfig); $tableIsGood = false; $useTable = Inflector::tableize($currentModelName); @@ -628,5 +609,34 @@ class ModelTask extends Shell { $this->out($i + 1 . ". " . $this->_modelNames[$i]); } } + +/** + * Forces the user to specify the model he wants to bake, and returns the selected model name. + * + * @return the model name + */ + function __getModelName($useDbConfig) { + $this->__doList($useDbConfig); + + $enteredModel = ''; + + while ($enteredModel == '') { + $enteredModel = $this->in('Enter a number from the list above, or type in the name of another model.'); + + if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) { + $this->out('Error:'); + $this->out("The model name you supplied was empty, or the number \nyou selected was not an option. Please try again."); + $enteredModel = ''; + } + } + + if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) { + $currentModelName = $this->_modelNames[intval($enteredModel) - 1]; + } else { + $currentModelName = $enteredModel; + } + + return $currentModelName; + } } ?> \ No newline at end of file diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index aa1380b0a..a6130601c 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -49,28 +49,7 @@ class ViewTask extends BakeShell { $wannaUseSession = 'y'; $wannaDoScaffold = 'y'; - - $useDbConfig = 'default'; - $this->__doList($useDbConfig, 'Controllers'); - - $enteredController = ''; - - while ($enteredController == '') { - $enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.'); - - if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) { - $this->out('Error:'); - $this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again."); - $enteredController = ''; - } - } - - if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) { - $controllerName = $this->_controllerNames[intval($enteredController) - 1]; - } else { - $controllerName = Inflector::camelize($enteredController); - } - + $controllerName = $this->__getControllerName(); $controllerPath = low(Inflector::underscore($controllerName)); $doItInteractive = $this->in("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite {$controllerName} views if it exist.", array('y','n'), 'y'); @@ -542,4 +521,34 @@ class ViewTask extends BakeShell { $this->out($i + 1 . ". " . $this->_controllerNames[$i]); } } + +/** + * Forces the user to specify the controller for which he wants to bake views, and returns the selected controller name. + * + * @return the controller name + */ + function __getControllerName() { + $useDbConfig = 'default'; + $this->__doList($useDbConfig, 'Controllers'); + + $enteredController = ''; + + while ($enteredController == '') { + $enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.'); + + if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) { + $this->out('Error:'); + $this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again."); + $enteredController = ''; + } + } + + if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) { + $controllerName = $this->_controllerNames[intval($enteredController) - 1]; + } else { + $controllerName = Inflector::camelize($enteredController); + } + + return $controllerName; + } } \ No newline at end of file