mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
bake: add list of controllers for controllers and view baking, just like models.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3698 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
3e2c52a5ab
commit
cf81d3077a
1 changed files with 72 additions and 32 deletions
|
@ -371,7 +371,6 @@ class Bake {
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->interactive = true;
|
$this->interactive = true;
|
||||||
|
|
||||||
$useDbConfig = 'default';
|
|
||||||
$useTable = null;
|
$useTable = null;
|
||||||
$primaryKey = 'id';
|
$primaryKey = 'id';
|
||||||
$validate = array();
|
$validate = array();
|
||||||
|
@ -381,25 +380,9 @@ class Bake {
|
||||||
{
|
{
|
||||||
$useDbConfig = $this->getInput('Please provide the name of the connection you wish to use.');
|
$useDbConfig = $this->getInput('Please provide the name of the connection you wish to use.');
|
||||||
}*/
|
}*/
|
||||||
$db =& ConnectionManager::getDataSource($useDbConfig);
|
$useDbConfig = 'default';
|
||||||
$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
|
$this->doList($useDbConfig);
|
||||||
if ($usePrefix) {
|
|
||||||
$tables = array();
|
|
||||||
foreach ($db->listSources() as $table) {
|
|
||||||
if (!strncmp($table, $usePrefix, strlen($usePrefix))) {
|
|
||||||
$tables[] = substr($table, strlen($usePrefix));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$tables = $db->listSources();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->stdout('Possible models based on your current database:');
|
|
||||||
$__modelNames = array();
|
|
||||||
for ($i = 0; $i < count($tables); $i++) {
|
|
||||||
$__modelNames[] = $this->__modelName($tables[$i]);
|
|
||||||
$this->stdout($i + 1 . ". " . $this->__modelName($tables[$i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
$enteredModel = '';
|
$enteredModel = '';
|
||||||
|
|
||||||
|
@ -776,16 +759,28 @@ class Bake {
|
||||||
$wannaUseSession = 'y';
|
$wannaUseSession = 'y';
|
||||||
$wannaDoScaffold = 'y';
|
$wannaDoScaffold = 'y';
|
||||||
|
|
||||||
$controllerName = '';
|
|
||||||
while ($controllerName == '') {
|
|
||||||
$controllerName = $this->getInput('Controller Name? (plural)');
|
|
||||||
|
|
||||||
if ($controllerName == '') {
|
$useDbConfig = 'default';
|
||||||
$this->stdout('The controller name you supplied was empty. Please try again.');
|
$this->doList($useDbConfig, 'Controllers');
|
||||||
|
|
||||||
|
$enteredController = '';
|
||||||
|
|
||||||
|
while ($enteredController == '') {
|
||||||
|
$enteredController = $this->getInput('Enter a number from the list above, or type in the name of another controller.');
|
||||||
|
|
||||||
|
if ($enteredController == '' || intval($enteredController) > $i) {
|
||||||
|
$this->stdout('Error:');
|
||||||
|
$this->stdout("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) <= $i ) {
|
||||||
|
$controllerName = $this->__controllerName($tables[intval($enteredController) - 1]);
|
||||||
|
} else {
|
||||||
|
$controllerName = $enteredController;
|
||||||
|
}
|
||||||
$controllerPath = $this->__controllerPath($controllerName);
|
$controllerPath = $this->__controllerPath($controllerName);
|
||||||
$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');
|
$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');
|
||||||
|
|
||||||
|
@ -1134,16 +1129,27 @@ class Bake {
|
||||||
$wannaUseSession = 'y';
|
$wannaUseSession = 'y';
|
||||||
$wannaDoScaffolding = 'y';
|
$wannaDoScaffolding = 'y';
|
||||||
|
|
||||||
$controllerName = '';
|
$useDbConfig = 'default';
|
||||||
while ($controllerName == '') {
|
$this->doList($useDbConfig, 'Controllers');
|
||||||
$controllerName = $this->getInput('Controller name? Remember that Cake controller names are plural.');
|
|
||||||
|
|
||||||
if ($controllerName == '') {
|
$enteredController = '';
|
||||||
$this->stdout('The controller name you supplied was empty. Please try again.');
|
|
||||||
|
while ($enteredController == '') {
|
||||||
|
$enteredController = $this->getInput('Enter a number from the list above, or type in the name of another controller.');
|
||||||
|
|
||||||
|
if ($enteredController == '' || intval($enteredController) > $i) {
|
||||||
|
$this->stdout('Error:');
|
||||||
|
$this->stdout("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) <= $i ) {
|
||||||
|
$controllerName = $this->__controllerName($tables[intval($enteredController) - 1]);
|
||||||
|
} else {
|
||||||
|
$controllerName = $enteredController;
|
||||||
|
}
|
||||||
$controllerPath = $this->__controllerPath($controllerName);
|
$controllerPath = $this->__controllerPath($controllerName);
|
||||||
$controllerName = $this->__controllerName($controllerName);
|
|
||||||
|
|
||||||
$doItInteractive = $this->getInput("Would you like bake to build your controller interactively?\nWarning: Choosing no will overwrite {$controllerClassName} controller if it exist.", array('y','n'), 'y');
|
$doItInteractive = $this->getInput("Would you like bake to build your controller interactively?\nWarning: Choosing no will overwrite {$controllerClassName} controller if it exist.", array('y','n'), 'y');
|
||||||
|
|
||||||
|
@ -2580,6 +2586,40 @@ class Bake {
|
||||||
function __pluralHumanName($name) {
|
function __pluralHumanName($name) {
|
||||||
return Inflector::humanize(Inflector::underscore(Inflector::pluralize($name)));
|
return Inflector::humanize(Inflector::underscore(Inflector::pluralize($name)));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* outputs the a list of model or controller options
|
||||||
|
*
|
||||||
|
* @param string $useDbConfig
|
||||||
|
* @param string $type = Models or Controllers
|
||||||
|
* @return output
|
||||||
|
*/
|
||||||
|
function doList($useDbConfig = 'default', $type = 'Models') {
|
||||||
|
$db =& ConnectionManager::getDataSource($useDbConfig);
|
||||||
|
$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
|
||||||
|
if ($usePrefix) {
|
||||||
|
$tables = array();
|
||||||
|
foreach ($db->listSources() as $table) {
|
||||||
|
if (!strncmp($table, $usePrefix, strlen($usePrefix))) {
|
||||||
|
$tables[] = substr($table, strlen($usePrefix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$tables = $db->listSources();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->stdout('Possible controllers based on your current database:');
|
||||||
|
$this->__controllerNames = array();
|
||||||
|
$this->__modelNames = array();
|
||||||
|
for ($i = 0; $i < count($tables); $i++) {
|
||||||
|
if($type == 'Controllers') {
|
||||||
|
$this->__controllerNames[] = $this->__controllerName($tables[$i]);
|
||||||
|
$this->stdout($i + 1 . ". " . $this->__controllerNames[$i]);
|
||||||
|
} else {
|
||||||
|
$this->__modelNames[] = $this->__modelName($tables[$i]);
|
||||||
|
$this->stdout($i + 1 . ". " . $this->__modelNames[$i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Add table
Reference in a new issue