Updating Bake to create admin route in core.php if not already set and admin routing option is used.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3669 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-10-14 18:07:52 +00:00
parent 8b23234b53
commit 3d47887211

View file

@ -678,8 +678,20 @@ class Bake {
if(defined('CAKE_ADMIN')) {
$admin = CAKE_ADMIN . '_';
} else {
$adminRoute = '';
$this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
$this->stdout('What would you like the admin route to be?');
$this->stdout('Example: www.example.com/admin/controller');
while ($adminRoute == '') {
$adminRoute = $this->getInput("What would you like the admin route to be?", null, 'admin');
}
if($this->__addAdminRoute($adminRoute) !== true){
$this->stdout('Unable to write to /app/config/core.php.');
$this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
exit();
} else {
$admin = $adminRoute . '_';
}
}
}
if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoScaffold) == 'yes') {
@ -1048,8 +1060,20 @@ class Bake {
if(defined('CAKE_ADMIN')) {
$admin = CAKE_ADMIN.'_';
} else {
$adminRoute = '';
$this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
exit;
$this->stdout('What would you like the admin route to be?');
$this->stdout('Example: www.example.com/admin/controller');
while ($adminRoute == '') {
$adminRoute = $this->getInput("What would you like the admin route to be?", null, 'admin');
}
if($this->__addAdminRoute($adminRoute) !== true){
$this->stdout('Unable to write to /app/config/core.php.');
$this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
exit();
} else {
$admin = $adminRoute . '_';
}
}
}
@ -2278,6 +2302,21 @@ class Bake {
}
return true;
}
function __addAdminRoute($name){
$file = file_get_contents(CONFIGS.'core.php');
if (preg_match('%([/\\t\\x20]*define\\(\'CAKE_ADMIN\',[\\t\\x20\'a-z]*\\);)%', $file, $match)) {
$result = str_replace($match[0], 'define(\'CAKE_ADMIN\', \''.$name.'\');', $file);
if(file_put_contents(CONFIGS.'core.php', $result)){
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* Outputs an ASCII art banner to standard output.
*