diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index 1516b7e36..9affcdc40 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -86,17 +86,17 @@ class ControllerTask extends Shell { $this->out(__('Baking basic crud methods for ', true) . $controller); $actions = $this->bakeActions($controller); } elseif (!empty($this->args[1]) && $this->args[1] == 'admin') { - $admin = $this->Project->getAdmin(); + $admin = $this->Project->getPrefix(); if ($admin) { - $this->out('Adding ' . Configure::read('Routing.admin') .' methods'); - $actions= $this->bakeActions($controller, $admin); + $this->out(sprintf(__('Adding %s methods', true), $admin)); + $actions = $this->bakeActions($controller, $admin); } } if (!empty($this->args[2]) && $this->args[2] == 'admin') { - $admin = $this->Project->getAdmin(); + $admin = $this->Project->getPrefix(); if ($admin) { - $this->out('Adding ' . Configure::read('Routing.admin') .' methods'); + $this->out(sprintf(__('Adding %s methods', true), $admin)); $actions .= "\n" . $this->bakeActions($controller, $admin); } } @@ -194,7 +194,7 @@ class ControllerTask extends Shell { $actions = $this->bakeActions($controllerName, null, strtolower($wannaUseSession) == 'y'); } if (strtolower($wannaBakeAdminCrud) == 'y') { - $admin = $this->Project->getAdmin(); + $admin = $this->Project->getPrefix(); $actions .= $this->bakeActions($controllerName, $admin, strtolower($wannaUseSession) == 'y'); } diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index b6289ccd4..609282038 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -351,7 +351,8 @@ class ModelTask extends Shell { $options = $choices = array(); if (class_exists('Validation')) { $parent = get_class_methods(get_parent_class('Validation')); - $options = array_diff(get_class_methods('Validation'), $parent); + $options = get_class_methods('Validation'); + $options = array_diff($options, $parent); } sort($options); $default = 1; diff --git a/cake/console/libs/tasks/project.php b/cake/console/libs/tasks/project.php index 6083a1055..d1f4be785 100644 --- a/cake/console/libs/tasks/project.php +++ b/cake/console/libs/tasks/project.php @@ -258,10 +258,10 @@ class ProjectTask extends Shell { $path = (empty($this->configPath)) ? CONFIGS : $this->configPath; $File =& new File($path . 'core.php'); $contents = $File->read(); - if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.admin\',[\\t\\x20\'a-z]*\\);)%', $contents, $match)) { - $result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.admin\', \''.$name.'\');', $contents); + if (preg_match('%([/\\t\\x20]*Configure::write\(\'Routing.prefixes\',[\\t\\x20\'a-z,\)\(]*\\);)%', $contents, $match)) { + $result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.prefixes\', array(\''.$name.'\'));', $contents); if ($File->write($result)) { - Configure::write('Routing.admin', $name); + Configure::write('Routing.prefixes', array($name)); return true; } else { return false; @@ -277,22 +277,31 @@ class ProjectTask extends Shell { * @return string Admin route to use * @access public */ - function getAdmin() { + function getPrefix() { $admin = ''; - $cakeAdmin = null; - $adminRoute = Configure::read('Routing.admin'); - if (!empty($adminRoute)) { - return $adminRoute . '_'; + $prefixes = Configure::read('Routing.prefixes'); + if (!empty($prefixes)) { + if (count($prefixes) == 1) { + return $prefixes[0] . '_'; + } + $options = array(); + foreach ($prefixes as $i => $prefix) { + $options[] = $i + 1; + $this->out($i + 1 . '. ' . $prefix); + } + $selection = $this->in(__('Please choose a prefix to bake with.', true), $options, 1); + return $prefixes[$selection - 1] . '_'; } - $this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.'); - $this->out(__('What would you like the admin route to be?', true)); + + $this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.'); + $this->out(__('What would you like the prefix route to be?', true)); $this->out(__('Example: www.example.com/admin/controller', true)); while ($admin == '') { - $admin = $this->in(__("What would you like the admin route to be?", true), null, 'admin'); + $admin = $this->in(__("What would you like the prefix route to be?", true), null, 'admin'); } if ($this->cakeAdmin($admin) !== true) { $this->out(__('Unable to write to /app/config/core.php.', true)); - $this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.'); + $this->out('You need to enable Configure::write(\'Routing.prefixes\',array(\'admin\')) in /app/config/core.php to use prefix routing.'); $this->_stop(); } return $admin . '_'; diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index 6cc2ff860..cb7bf1d59 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -156,13 +156,13 @@ class ViewTask extends Shell { $scaffoldActions = true; $methods = $this->scaffoldActions; } - $adminRoute = Configure::read('Routing.admin'); + $adminRoute = $this->Project->getPrefix(); foreach ($methods as $i => $method) { if ($adminRoute && isset($this->params['admin'])) { if ($scaffoldActions) { - $methods[$i] = $adminRoute . '_' . $method; + $methods[$i] = $adminRoute . $method; continue; - } elseif (strpos($method, $adminRoute . '_') === false) { + } elseif (strpos($method, $adminRoute) === false) { unset($methods[$i]); } } @@ -233,7 +233,7 @@ class ViewTask extends Shell { $this->bakeActions($actions, $vars); } if (strtolower($wannaDoAdmin) == 'y') { - $admin = $this->Project->getAdmin(); + $admin = $this->Project->getPrefix(); $regularActions = $this->scaffoldActions; $adminActions = array(); foreach ($regularActions as $action) { @@ -403,9 +403,11 @@ class ViewTask extends Shell { return $this->template; } $template = $action; - $adminRoute = Configure::read('Routing.admin'); - if (!empty($adminRoute) && strpos($template, $adminRoute) !== false) { - $template = str_replace($adminRoute . '_', '', $template); + $prefixes = Configure::read('Routing.prefixes'); + foreach ((array)$prefixes as $prefix) { + if (strpos($template, $prefix) !== false) { + $template = str_replace($prefix . '_', '', $template); + } } if (in_array($template, array('add', 'edit'))) { $template = 'form'; diff --git a/cake/console/templates/default/views/form.ctp b/cake/console/templates/default/views/form.ctp index 264221c3d..941d7aa6a 100644 --- a/cake/console/templates/default/views/form.ctp +++ b/cake/console/templates/default/views/form.ctp @@ -26,7 +26,7 @@