Skip to content
Permalink
Browse files

Adding `cake bake controller all`

  • Loading branch information...
markstory committed Apr 28, 2009
1 parent 798a9d5 commit f0543987e1608b5df334101ea9c42d536705a112
Showing with 37 additions and 9 deletions.
  1. +37 −9 cake/console/libs/tasks/controller.php
@@ -70,6 +70,9 @@ function execute() {
}
if (isset($this->args[0])) {
if (strtolower($this->args[0]) == 'all') {
return $this->all();
}
$controller = Inflector::camelize($this->args[0]);
$actions = null;
if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
@@ -95,6 +98,28 @@ function execute() {
}
}
}
/**
* Bake All the controllers at once. Will only bake controllers for models that exist.
*
* @access public
* @return void
**/
function all() {
$ds = 'default';
$ds = 'default';
if (isset($this->params['connection'])) {
$ds = $this->params['connection'];
}
$controllers = $this->listAll($ds, false);
foreach ($this->__tables as $table) {
$model = $this->_modelName($table);
$controller = $this->_controllerName($model);
if (App::import('Model', $model)) {
$actions = $this->bakeActions($controller);
$this->bake($controller, $actions);
}
}
}
/**
* Interactive
*
@@ -488,10 +513,11 @@ function bakeTest($className) {
* Outputs and gets the list of possible models or controllers from database
*
* @param string $useDbConfig Database configuration name
* @param boolean $interactive Whether you are using listAll interactively and want options output.
* @return array Set of controllers
* @access public
*/
function listAll($useDbConfig = 'default') {
function listAll($useDbConfig = 'default', $interactive = true) {
$db =& ConnectionManager::getDataSource($useDbConfig);
$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
if ($usePrefix) {
@@ -511,14 +537,16 @@ function listAll($useDbConfig = 'default') {
}
$this->__tables = $tables;
$this->out('Possible Controllers based on your current database:');
$this->_controllerNames = array();
$count = count($tables);
for ($i = 0; $i < $count; $i++) {
$this->_controllerNames[] = $this->_controllerName($this->_modelName($tables[$i]));
$this->out($i + 1 . ". " . $this->_controllerNames[$i]);
}
return $this->_controllerNames;
if ($interactive == true) {
$this->out('Possible Controllers based on your current database:');
$this->_controllerNames = array();
$count = count($tables);
for ($i = 0; $i < $count; $i++) {
$this->_controllerNames[] = $this->_controllerName($this->_modelName($tables[$i]));
$this->out($i + 1 . ". " . $this->_controllerNames[$i]);
}
return $this->_controllerNames;
}
}
/**

0 comments on commit f054398

Please sign in to comment.
You can’t perform that action at this time.