bake 1.2 : removed _ _() for now, added admin to urls for admin methods and views

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3722 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2006-10-20 01:19:46 +00:00
parent 755e3dbae1
commit 20bdd8181b

View file

@ -302,7 +302,7 @@ class Bake {
$login = ''; $login = '';
while ($login == '') { while ($login == '') {
$login = $this->getInput('What is the database username?', null, 'root'); $login = $this->getInput('What is the database username?');
if ($login == '') { if ($login == '') {
$this->stdout('The database username you supplied was empty. Please try again.'); $this->stdout('The database username you supplied was empty. Please try again.');
@ -312,7 +312,7 @@ class Bake {
$blankPassword = false; $blankPassword = false;
while ($password == '' && $blankPassword == false) { while ($password == '' && $blankPassword == false) {
$password = $this->getInput('What is the database password?', null, ''); $password = $this->getInput('What is the database password?');
if ($password == '') { if ($password == '') {
$blank = $this->getInput('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n'); $blank = $this->getInput('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
if($blank == 'y') if($blank == 'y')
@ -324,7 +324,7 @@ class Bake {
$database = ''; $database = '';
while ($database == '') { while ($database == '') {
$database = $this->getInput('What is the name of the database you will be using?', null, 'cake'); $database = $this->getInput('What is the name of the database you will be using?');
if ($database == '') { if ($database == '') {
$this->stdout('The database name you supplied was empty. Please try again.'); $this->stdout('The database name you supplied was empty. Please try again.');
@ -795,6 +795,7 @@ class Bake {
} }
$admin = null; $admin = null;
$admin_url = null;
if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoScaffold) == 'yes') { if (strtolower($wannaDoScaffold) == 'y' || strtolower($wannaDoScaffold) == 'yes') {
$wannaDoAdmin = $this->getInput("Would you like to create the views for admin routing?", array('y','n'), 'n'); $wannaDoAdmin = $this->getInput("Would you like to create the views for admin routing?", array('y','n'), 'n');
} }
@ -803,6 +804,7 @@ class Bake {
require(CONFIGS.'core.php'); require(CONFIGS.'core.php');
if(defined('CAKE_ADMIN')) { if(defined('CAKE_ADMIN')) {
$admin = CAKE_ADMIN . '_'; $admin = CAKE_ADMIN . '_';
$admin_url = '/'.CAKE_ADMIN;
} else { } else {
$adminRoute = ''; $adminRoute = '';
$this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.'); $this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
@ -817,6 +819,7 @@ class Bake {
exit(); exit();
} else { } else {
$admin = $adminRoute . '_'; $admin = $adminRoute . '_';
$admin_url = '/'.$adminRoute;
} }
} }
} }
@ -864,14 +867,14 @@ class Bake {
} }
} }
$indexView .= "<div class=\"{$pluralName}\">\n"; $indexView .= "<div class=\"{$pluralName}\">\n";
$indexView .= "<h2><?php __('List " . $pluralHumanName . "');?></h2>\n\n"; $indexView .= "<h2>List " . $pluralHumanName . "</h2>\n\n";
$indexView .= "<table cellpadding=\"0\" cellspacing=\"0\">\n"; $indexView .= "<table cellpadding=\"0\" cellspacing=\"0\">\n";
$indexView .= "<tr>\n"; $indexView .= "<tr>\n";
foreach ($fieldNames as $fieldName) { foreach ($fieldNames as $fieldName) {
$indexView .= "\t<th><?php __('".$fieldName['prompt']."');?></th>\n"; $indexView .= "\t<th>".$fieldName['prompt']."</th>\n";
} }
$indexView .= "\t<th><?php __('Actions');?></th>\n"; $indexView .= "\t<th>Actions</th>\n";
$indexView .= "</tr>\n"; $indexView .= "</tr>\n";
$indexView .= "<?php foreach (\${$pluralName} as \${$singularName}): ?>\n"; $indexView .= "<?php foreach (\${$pluralName} as \${$singularName}): ?>\n";
$indexView .= "<tr>\n"; $indexView .= "<tr>\n";
@ -885,25 +888,25 @@ class Bake {
$otherControllerPath = $this->__controllerPath($otherControllerName); $otherControllerPath = $this->__controllerPath($otherControllerName);
if(is_object($otherModelObj)) { if(is_object($otherModelObj)) {
$displayField = $otherModelObj->getDisplayField(); $displayField = $otherModelObj->getDisplayField();
$indexView .= "\t<td>&nbsp;<?php echo \$html->link(__(\$".$singularName."['{$alias[$count]}']['{$displayField}'], true), '/" . $otherControllerPath . "/view/' .\$".$singularName."['{$alias[$count]}']['{$otherModelObj->primaryKey}'])?></td>\n"; $indexView .= "\t<td>&nbsp;<?php echo \$html->link(\$".$singularName."['{$alias[$count]}']['{$displayField}'], '{$admin_url}/" . $otherControllerPath . "/view/' .\$".$singularName."['{$alias[$count]}']['{$otherModelObj->primaryKey}'])?></td>\n";
} else { } else {
$indexView .= "\t<td><?php __(\$".$singularName."['{$modelObj->name}']['{$field}']); ?></td>\n"; $indexView .= "\t<td><?php echo \$".$singularName."['{$modelObj->name}']['{$field}']; ?></td>\n";
} }
$count++; $count++;
} else { } else {
$indexView .= "\t<td><?php __(\$".$singularName."['{$modelObj->name}']['{$field}']); ?></td>\n"; $indexView .= "\t<td><?php echo \$".$singularName."['{$modelObj->name}']['{$field}']; ?></td>\n";
} }
} }
$indexView .= "\t<td nowrap>\n"; $indexView .= "\t<td nowrap>\n";
$indexView .= "\t\t<?php echo \$html->link(__('View', true),'/{$controllerPath}/view/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])?>\n"; $indexView .= "\t\t<?php echo \$html->link('View','{$admin_url}/{$controllerPath}/view/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])?>\n";
$indexView .= "\t\t<?php echo \$html->link(__('Edit', true),'/{$controllerPath}/edit/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])?>\n"; $indexView .= "\t\t<?php echo \$html->link('Edit','{$admin_url}/{$controllerPath}/edit/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])?>\n";
$indexView .= "\t\t<?php echo \$html->link(__('Delete', true),'/{$controllerPath}/delete/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'], null, __('Are you sure you want to delete: id ' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'], true))?>\n"; $indexView .= "\t\t<?php echo \$html->link('Delete','{$admin_url}/{$controllerPath}/delete/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'], null, 'Are you sure you want to delete id ' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])?>\n";
$indexView .= "\t</td>\n"; $indexView .= "\t</td>\n";
$indexView .= "</tr>\n"; $indexView .= "</tr>\n";
$indexView .= "<?php endforeach; ?>\n"; $indexView .= "<?php endforeach; ?>\n";
$indexView .= "</table>\n\n"; $indexView .= "</table>\n\n";
$indexView .= "<ul class=\"actions\">\n"; $indexView .= "<ul class=\"actions\">\n";
$indexView .= "\t<li><?php echo \$html->link(__('New {$singularHumanName}', true), '/{$controllerPath}/add'); ?></li>\n"; $indexView .= "\t<li><?php echo \$html->link('New {$singularHumanName}', '{$admin_url}/{$controllerPath}/add'); ?></li>\n";
$indexView .= "</ul>\n"; $indexView .= "</ul>\n";
$indexView .= "</div>"; $indexView .= "</div>";
@ -911,11 +914,11 @@ class Bake {
$viewView = null; $viewView = null;
$viewView .= "<div class=\"{$singularName}\">\n"; $viewView .= "<div class=\"{$singularName}\">\n";
$viewView .= "<h2><?php __('View " . $singularHumanName . "');?></h2>\n\n"; $viewView .= "<h2>View " . $singularHumanName . "</h2>\n\n";
$viewView .= "<dl>\n"; $viewView .= "<dl>\n";
$count = 0; $count = 0;
foreach($fieldNames as $field => $value) { foreach($fieldNames as $field => $value) {
$viewView .= "\t<dt><?php __('" . $value['prompt'] . "');</dt>\n"; $viewView .= "\t<dt>" . $value['prompt'] . "</dt>\n";
if(isset($value['foreignKey'])) { if(isset($value['foreignKey'])) {
$otherModelName = $this->__modelName($value['model']); $otherModelName = $this->__modelName($value['model']);
$otherModelKey = Inflector::underscore($otherModelName); $otherModelKey = Inflector::underscore($otherModelName);
@ -923,18 +926,18 @@ class Bake {
$otherControllerName = $this->__controllerName($otherModelName); $otherControllerName = $this->__controllerName($otherModelName);
$otherControllerPath = $this->__controllerPath($otherControllerName); $otherControllerPath = $this->__controllerPath($otherControllerName);
$displayField = $otherModelObj->getDisplayField(); $displayField = $otherModelObj->getDisplayField();
$viewView .= "\t<dd>&nbsp;<?php echo \$html->link(__(\$".$singularName."['{$alias[$count]}']['{$displayField}'], true), '/" . $otherControllerPath . "/view/' .\$".$singularName."['{$alias[$count]}']['{$otherModelObj->primaryKey}']); ?></dd>\n"; $viewView .= "\t<dd>&nbsp;<?php echo \$html->link(\$".$singularName."['{$alias[$count]}']['{$displayField}'], '{$admin_url}/" . $otherControllerPath . "/view/' .\$".$singularName."['{$alias[$count]}']['{$otherModelObj->primaryKey}'])?></dd>\n";
$count++; $count++;
} else { } else {
$viewView .= "\t<dd>&nbsp;<?php __(\$".$singularName."['{$modelObj->name}']['{$field}']);?></dd>\n"; $viewView .= "\t<dd>&nbsp;<?php echo \$".$singularName."['{$modelObj->name}']['{$field}']?></dd>\n";
} }
} }
$viewView .= "</dl>\n"; $viewView .= "</dl>\n";
$viewView .= "<ul class=\"actions\">\n"; $viewView .= "<ul class=\"actions\">\n";
$viewView .= "\t<li><?php echo \$html->link(__('Edit " . $singularHumanName . "', true), '/{$controllerPath}/edit/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}']) ?> </li>\n"; $viewView .= "\t<li><?php echo \$html->link('Edit " . $singularHumanName . "', '{$admin_url}/{$controllerPath}/edit/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}']) ?> </li>\n";
$viewView .= "\t<li><?php echo \$html->link(__('Delete " . $singularHumanName . "', true), '/{$controllerPath}/delete/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'], null, __('Are you sure you want to delete: id ' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'] . '?', true)); ?> </li>\n"; $viewView .= "\t<li><?php echo \$html->link('Delete " . $singularHumanName . "', '{$admin_url}/{$controllerPath}/delete/' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'], null, 'Are you sure you want to delete: id ' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'] . '?') ?> </li>\n";
$viewView .= "\t<li><?php echo \$html->link(__('List " . $pluralHumanName ."', true), '/{$controllerPath}/index') ?> </li>\n"; $viewView .= "\t<li><?php echo \$html->link('List " . $pluralHumanName ."', '{$admin_url}/{$controllerPath}/index') ?> </li>\n";
$viewView .= "\t<li><?php echo \$html->link(__('New " . $singularHumanName . "', true), '/{$controllerPath}/add') ?> </li>\n"; $viewView .= "\t<li><?php echo \$html->link('New " . $singularHumanName . "', '{$admin_url}/{$controllerPath}/add') ?> </li>\n";
foreach( $fieldNames as $field => $value ) { foreach( $fieldNames as $field => $value ) {
if( isset( $value['foreignKey'] ) ) { if( isset( $value['foreignKey'] ) ) {
$otherModelName = $this->__modelName($value['model']); $otherModelName = $this->__modelName($value['model']);
@ -943,8 +946,8 @@ class Bake {
$otherControllerPath = $this->__controllerPath($otherControllerName); $otherControllerPath = $this->__controllerPath($otherControllerName);
$otherSingularHumanName = $this->__singularHumanName($value['controller']); $otherSingularHumanName = $this->__singularHumanName($value['controller']);
$otherPluralHumanName = $this->__pluralHumanName($value['controller']); $otherPluralHumanName = $this->__pluralHumanName($value['controller']);
$viewView .= "\t<li><?php echo \$html->link(__('List " . $otherSingularHumanName . "', true), '/" . $otherControllerPath . "/index/')?> </li>\n"; $viewView .= "\t<li><?php echo \$html->link('List " . $otherSingularHumanName . "', '{$admin_url}/" . $otherControllerPath . "/index/')?> </li>\n";
$viewView .= "\t<li><?php echo \$html->link(__('New " . $otherPluralHumanName . "', true), '/" . $otherControllerPath . "/add/')?> </li>\n"; $viewView .= "\t<li><?php echo \$html->link('New " . $otherPluralHumanName . "', '{$admin_url}/" . $otherControllerPath . "/add/')?> </li>\n";
} }
} }
} }
@ -964,18 +967,18 @@ class Bake {
$otherSingularHumanName = $this->__singularHumanName($associationName); $otherSingularHumanName = $this->__singularHumanName($associationName);
$viewView .= "<div class=\"related\">\n"; $viewView .= "<div class=\"related\">\n";
$viewView .= "<h3><?php __('Related " . $otherPluralHumanName . "'); ?></h3>\n"; $viewView .= "<h3>Related " . $otherPluralHumanName . "</h3>\n";
$viewView .= "<?php if(!empty(\$".$singularName."['{$associationName}'])): ?>\n"; $viewView .= "<?php if(!empty(\$".$singularName."['{$associationName}'])): ?>\n";
$viewView .= "<dl>\n"; $viewView .= "<dl>\n";
$viewView .= "\t<?php foreach(\$".$singularName."['{$associationName}'] as \$field => \$value): ?>\n"; $viewView .= "\t<?php foreach(\$".$singularName."['{$associationName}'] as \$field => \$value): ?>\n";
$viewView .= "\t\t<dt><?php __(\$field); ?></dt>\n"; $viewView .= "\t\t<dt><?php echo \$field ?></dt>\n";
$viewView .= "\t\t<dd>&nbsp;<?php __(\$value); ?></dd>\n"; $viewView .= "\t\t<dd>&nbsp;<?php echo \$value ?></dd>\n";
$viewView .= "\t<?php endforeach; ?>\n"; $viewView .= "\t<?php endforeach; ?>\n";
$viewView .= "</dl>\n"; $viewView .= "</dl>\n";
$viewView .= "<?php endif; ?>\n"; $viewView .= "<?php endif; ?>\n";
$viewView .= "<ul class=\"actions\">\n"; $viewView .= "<ul class=\"actions\">\n";
$viewView .= "\t<li><?php echo \$html->link(__('Edit " . $otherSingularHumanName . "', true), '/" .$otherControllerPath."/edit/' . \$".$singularName."['{$associationName}']['" . $modelObj->{$otherModelName}->primaryKey . "']);?></li>\n"; $viewView .= "\t<li><?php echo \$html->link('Edit " . $otherSingularHumanName . "', '{$admin_url}/" .$otherControllerPath."/edit/' . \$".$singularName."['{$associationName}']['" . $modelObj->{$otherModelName}->primaryKey . "']);?></li>\n";
$viewView .= "\t<li><?php echo \$html->link(__('New " . $otherSingularHumanName . "', true), '/" .$otherControllerPath."/add/');?> </li>\n"; $viewView .= "\t<li><?php echo \$html->link('New " . $otherSingularHumanName . "', '{$admin_url}/" .$otherControllerPath."/add/');?> </li>\n";
$viewView .= "</ul>\n"; $viewView .= "</ul>\n";
$viewView .= "</div>\n"; $viewView .= "</div>\n";
} }
@ -992,44 +995,44 @@ class Bake {
$otherModelObj =& ClassRegistry::getObject($otherModelKey); $otherModelObj =& ClassRegistry::getObject($otherModelKey);
$viewView .= "<div class=\"related\">\n"; $viewView .= "<div class=\"related\">\n";
$viewView .= "<h3><?php __('Related " . $otherPluralHumanName . "'); ?></h3>\n"; $viewView .= "<h3>Related " . $otherPluralHumanName . "</h3>\n";
$viewView .= "<?php if(!empty(\$".$singularName."['{$associationName}'])):?>\n"; $viewView .= "<?php if(!empty(\$".$singularName."['{$associationName}'])):?>\n";
$viewView .= "<table cellpadding=\"0\" cellspacing=\"0\">\n"; $viewView .= "<table cellpadding=\"0\" cellspacing=\"0\">\n";
$viewView .= "<tr>\n"; $viewView .= "<tr>\n";
$viewView .= "<?php foreach(\$".$singularName."['{$associationName}']['0'] as \$column => \$value): ?>\n"; $viewView .= "<?php foreach(\$".$singularName."['{$associationName}']['0'] as \$column => \$value): ?>\n";
$viewView .= "<th><?php __(\$column); ?></th>\n"; $viewView .= "<th><?php echo \$column?></th>\n";
$viewView .= "<?php endforeach; ?>\n"; $viewView .= "<?php endforeach; ?>\n";
$viewView .= "<th><?php __('Actions'); ?></th>\n"; $viewView .= "<th>Actions</th>\n";
$viewView .= "</tr>\n"; $viewView .= "</tr>\n";
$viewView .= "<?php foreach(\$".$singularName."['{$associationName}'] as \$".$otherSingularName."):?>\n"; $viewView .= "<?php foreach(\$".$singularName."['{$associationName}'] as \$".$otherSingularName."):?>\n";
$viewView .= "<tr>\n"; $viewView .= "<tr>\n";
$viewView .= "\t<?php foreach(\$".$otherSingularName." as \$column => \$value):?>\n"; $viewView .= "\t<?php foreach(\$".$otherSingularName." as \$column => \$value):?>\n";
$viewView .= "\t\t<td><?php __(\$value); ?></td>\n"; $viewView .= "\t\t<td><?php echo \$value;?></td>\n";
$viewView .= "\t<?php endforeach;?>\n"; $viewView .= "\t<?php endforeach;?>\n";
$viewView .= "\t<td nowrap>\n"; $viewView .= "\t<td nowrap>\n";
$viewView .= "\t\t<?php echo \$html->link(__('View', true), '/" . $otherControllerPath . "/view/' . \$".$otherSingularName."['{$otherModelObj->primaryKey}']);?>\n"; $viewView .= "\t\t<?php echo \$html->link('View', '{$admin_url}/" . $otherControllerPath . "/view/' . \$".$otherSingularName."['{$otherModelObj->primaryKey}']);?>\n";
$viewView .= "\t\t<?php echo \$html->link(__('Edit', true), '/" . $otherControllerPath . "/edit/' . \$".$otherSingularName."['{$otherModelObj->primaryKey}']);?>\n"; $viewView .= "\t\t<?php echo \$html->link('Edit', '{$admin_url}/" . $otherControllerPath . "/edit/' . \$".$otherSingularName."['{$otherModelObj->primaryKey}']);?>\n";
$viewView .= "\t\t<?php echo \$html->link(__('Delete', true), '/" . $otherControllerPath . "/delete/' . \$".$otherSingularName."['{$otherModelObj->primaryKey}'], null, __('Are you sure you want to delete: id ' . \$".$otherSingularName."['{$otherModelObj->primaryKey}'] . '?', true));?>\n"; $viewView .= "\t\t<?php echo \$html->link('Delete', '{$admin_url}/" . $otherControllerPath . "/delete/' . \$".$otherSingularName."['{$otherModelObj->primaryKey}'], null, 'Are you sure you want to delete: id ' . \$".$otherSingularName."['{$otherModelObj->primaryKey}'] . '?');?>\n";
$viewView .= "\t</td>\n"; $viewView .= "\t</td>\n";
$viewView .= "</tr>\n"; $viewView .= "</tr>\n";
$viewView .= "<?php endforeach; ?>\n"; $viewView .= "<?php endforeach; ?>\n";
$viewView .= "</table>\n"; $viewView .= "</table>\n";
$viewView .= "<?php endif; ?>\n\n"; $viewView .= "<?php endif; ?>\n\n";
$viewView .= "<ul class=\"actions\">\n"; $viewView .= "<ul class=\"actions\">\n";
$viewView .= "\t<li><?php echo \$html->link(__('New " . $otherSingularHumanName . "', true), '/" .$otherControllerPath."/add/');?> </li>\n"; $viewView .= "\t<li><?php echo \$html->link('New " . $otherSingularHumanName . "', '{$admin_url}/" .$otherControllerPath."/add/');?> </li>\n";
$viewView .= "</ul>\n"; $viewView .= "</ul>\n";
$viewView .= "</div>\n"; $viewView .= "</div>\n";
} }
//-------------------------[ADD]-------------------------// //-------------------------[ADD]-------------------------//
$addView = null; $addView = null;
$addView .= "<h2><?php __('New " . $singularHumanName . "'); ?></h2>\n"; $addView .= "<h2>New " . $singularHumanName . "</h2>\n";
$addView .= "<form action=\"<?php echo \$html->url('/{$controllerPath}/add'); ?>\" method=\"post\">\n"; $addView .= "<form action=\"<?php echo \$html->url('{$admin_url}/{$controllerPath}/add'); ?>\" method=\"post\">\n";
$addView .= $this->generateFields($controllerObj->generateFieldNames(null, true)); $addView .= $this->generateFields($controllerObj->generateFieldNames(null, true));
$addView .= $this->generateSubmitDiv('Add'); $addView .= $this->generateSubmitDiv('Add');
$addView .= "</form>\n"; $addView .= "</form>\n";
$addView .= "<ul class=\"actions\">\n"; $addView .= "<ul class=\"actions\">\n";
$addView .= "<li><?php echo \$html->link(__('List {$pluralHumanName}', true), '/{$controllerPath}/index')?></li>\n"; $addView .= "<li><?php echo \$html->link('List {$pluralHumanName}', '{$admin_url}/{$controllerPath}/index')?></li>\n";
foreach ($modelObj->belongsTo as $associationName => $relation) { foreach ($modelObj->belongsTo as $associationName => $relation) {
$otherModelName = $this->__modelName($relation['className']); $otherModelName = $this->__modelName($relation['className']);
if($otherModelName != $currentModelName) { if($otherModelName != $currentModelName) {
@ -1037,22 +1040,22 @@ class Bake {
$otherControllerPath = $this->__controllerPath($otherModelName); $otherControllerPath = $this->__controllerPath($otherModelName);
$otherSingularName = $this->__singularName($associationName); $otherSingularName = $this->__singularName($associationName);
$otherPluralName = $this->__pluralHumanName($associationName); $otherPluralName = $this->__pluralHumanName($associationName);
$addView .= "<li><?php echo \$html->link(__('View " . $otherPluralName . "', true), '/" .$otherControllerPath."/index/');?></li>\n"; $addView .= "<li><?php echo \$html->link('View " . $otherPluralName . "', '{$admin_url}/" .$otherControllerPath."/index/');?></li>\n";
$addView .= "<li><?php echo \$html->link(__('Add " . $otherPluralName . "', true), '/" .$otherControllerPath."/add/');?></li>\n"; $addView .= "<li><?php echo \$html->link('Add " . $otherPluralName . "', '{$admin_url}/" .$otherControllerPath."/add/');?></li>\n";
} }
} }
$addView .= "</ul>\n"; $addView .= "</ul>\n";
//-------------------------[EDIT]-------------------------// //-------------------------[EDIT]-------------------------//
$editView = null; $editView = null;
$editView .= "<h2><?php __('Edit " . $singularHumanName . "'); ?></h2>\n"; $editView .= "<h2>Edit " . $singularHumanName . "</h2>\n";
$editView .= "<form action=\"<?php echo \$html->url('/{$controllerPath}/edit/'.\$html->tagValue('{$modelObj->name}/{$modelObj->primaryKey}')); ?>\" method=\"post\">\n"; $editView .= "<form action=\"<?php echo \$html->url('{$admin_url}/{$controllerPath}/edit/'.\$html->tagValue('{$modelObj->name}/{$modelObj->primaryKey}')); ?>\" method=\"post\">\n";
$editView .= $this->generateFields($controllerObj->generateFieldNames(null, true)); $editView .= $this->generateFields($controllerObj->generateFieldNames(null, true));
$editView .= "<?php echo \$html->hidden('{$modelObj->name}/{$modelObj->primaryKey}')?>\n"; $editView .= "<?php echo \$html->hidden('{$modelObj->name}/{$modelObj->primaryKey}')?>\n";
$editView .= $this->generateSubmitDiv('Save'); $editView .= $this->generateSubmitDiv('Save');
$editView .= "</form>\n"; $editView .= "</form>\n";
$editView .= "<ul class=\"actions\">\n"; $editView .= "<ul class=\"actions\">\n";
$editView .= "<li><?php echo \$html->link(__('Delete', true),'/{$controllerPath}/delete/' . \$html->tagValue('{$modelObj->name}/{$modelObj->primaryKey}'), null, __('Are you sure you want to delete: id ' . \$html->tagValue('{$modelObj->name}/{$modelObj->primaryKey}'), true));?>\n"; $editView .= "<li><?php echo \$html->link('Delete','{$admin_url}/{$controllerPath}/delete/' . \$html->tagValue('{$modelObj->name}/{$modelObj->primaryKey}'), null, 'Are you sure you want to delete: id ' . \$html->tagValue('{$modelObj->name}/{$modelObj->primaryKey}'));?>\n";
$editView .= "<li><?php echo \$html->link(__('List {$pluralHumanName}', true), '/{$controllerPath}/index')?></li>\n"; $editView .= "<li><?php echo \$html->link('List {$pluralHumanName}', '{$admin_url}/{$controllerPath}/index')?></li>\n";
foreach ($modelObj->belongsTo as $associationName => $relation) { foreach ($modelObj->belongsTo as $associationName => $relation) {
$otherModelName = $this->__modelName($relation['className']); $otherModelName = $this->__modelName($relation['className']);
if($otherModelName != $currentModelName) { if($otherModelName != $currentModelName) {
@ -1060,8 +1063,8 @@ class Bake {
$otherControllerPath = $this->__controllerPath($otherModelName); $otherControllerPath = $this->__controllerPath($otherModelName);
$otherSingularName = $this->__singularName($associationName); $otherSingularName = $this->__singularName($associationName);
$otherPluralName = $this->__pluralHumanName($associationName); $otherPluralName = $this->__pluralHumanName($associationName);
$editView .= "<li><?php echo \$html->link(__('View " . $otherPluralName . "', true), '/" .$otherControllerPath."/index/');?></li>\n"; $editView .= "<li><?php echo \$html->link('View " . $otherPluralName . "', '{$admin_url}/" .$otherControllerPath."/index/');?></li>\n";
$editView .= "<li><?php echo \$html->link(__('Add " . $otherPluralName . "', true), '/" .$otherControllerPath."/add/');?></li>\n"; $editView .= "<li><?php echo \$html->link('Add " . $otherPluralName . "', '{$admin_url}/" .$otherControllerPath."/add/');?></li>\n";
} }
} }
$editView .= "</ul>\n"; $editView .= "</ul>\n";
@ -1195,10 +1198,12 @@ class Bake {
} }
$admin = null; $admin = null;
$admin_url = null;
if ((strtolower($wannaDoAdmin) == 'y' || strtolower($wannaDoAdmin) == 'yes')) { if ((strtolower($wannaDoAdmin) == 'y' || strtolower($wannaDoAdmin) == 'yes')) {
require(CONFIGS.'core.php'); require(CONFIGS.'core.php');
if(defined('CAKE_ADMIN')) { if(defined('CAKE_ADMIN')) {
$admin = CAKE_ADMIN.'_'; $admin = CAKE_ADMIN.'_';
$admin_url = '/'.CAKE_ADMIN;
} else { } else {
$adminRoute = ''; $adminRoute = '';
$this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.'); $this->stdout('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
@ -1213,6 +1218,7 @@ class Bake {
exit(); exit();
} else { } else {
$admin = $adminRoute . '_'; $admin = $adminRoute . '_';
$admin_url = '/'.$adminRoute;
} }
} }
} }
@ -1309,10 +1315,10 @@ class Bake {
$actions .= "\tfunction {$admin}view(\$id = null) {\n"; $actions .= "\tfunction {$admin}view(\$id = null) {\n";
$actions .= "\t\tif(!\$id) {\n"; $actions .= "\t\tif(!\$id) {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\$this->Session->setFlash(__('Invalid ".Inflector::humanize($currentModelName)." id.', true));\n"; $actions .= "\t\t\t\$this->Session->setFlash('Invalid id for {$singularHumanName}.');\n";
$actions .= "\t\t\t\$this->redirect('/{$controllerPath}/index');\n"; $actions .= "\t\t\t\$this->redirect('{$admin_url}/{$controllerPath}/index');\n";
} else { } else {
$actions .= "\t\t\t\$this->flash(__('Invalid {$currentModelName} id.', '/{$controllerPath}/index', true));\n"; $actions .= "\t\t\t\$this->flash('Invalid id for {$singularHumanName}', '{$admin_url}/{$controllerPath}/index');\n";
} }
$actions .= "\t\t}\n"; $actions .= "\t\t}\n";
$actions .= "\t\t\$this->set('".$singularName."', \$this->{$currentModelName}->read(null, \$id));\n"; $actions .= "\t\t\$this->set('".$singularName."', \$this->{$currentModelName}->read(null, \$id));\n";
@ -1349,14 +1355,14 @@ class Bake {
$actions .= "\t\t\t\$this->cleanUpFields();\n"; $actions .= "\t\t\t\$this->cleanUpFields();\n";
$actions .= "\t\t\tif(\$this->{$currentModelName}->save(\$this->data)) {\n"; $actions .= "\t\t\tif(\$this->{$currentModelName}->save(\$this->data)) {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('The ".Inflector::humanize($currentModelName)." has been saved', true));\n"; $actions .= "\t\t\t\t\$this->Session->setFlash('The ".Inflector::humanize($currentModelName)." has been saved');\n";
$actions .= "\t\t\t\t\$this->redirect('/{$controllerPath}/index');\n"; $actions .= "\t\t\t\t\$this->redirect('{$admin_url}/{$controllerPath}/index');\n";
} else { } else {
$actions .= "\t\t\t\t\$this->flash(__('{$currentModelName} saved.', '/{$controllerPath}/index', true));\n"; $actions .= "\t\t\t\t\$this->flash('{$currentModelName} saved.', '{$admin_url}/{$controllerPath}/index');\n";
} }
$actions .= "\t\t\t} else {\n"; $actions .= "\t\t\t} else {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('Please correct errors below.', true));\n"; $actions .= "\t\t\t\t\$this->Session->setFlash('Please correct errors below.');\n";
} }
foreach($modelObj->hasAndBelongsToMany as $associationName => $relation) { foreach($modelObj->hasAndBelongsToMany as $associationName => $relation) {
@ -1391,10 +1397,10 @@ class Bake {
$actions .= "\t\tif(empty(\$this->data)) {\n"; $actions .= "\t\tif(empty(\$this->data)) {\n";
$actions .= "\t\t\tif(!\$id) {\n"; $actions .= "\t\t\tif(!\$id) {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('Invalid ".Inflector::humanize($currentModelName)." id.', true));\n"; $actions .= "\t\t\t\t\$this->Session->setFlash('Invalid id for {$singularHumanName}');\n";
$actions .= "\t\t\t\t\$this->redirect('/{$controllerPath}/index');\n"; $actions .= "\t\t\t\t\$this->redirect('{$admin_url}/{$controllerPath}/index');\n";
} else { } else {
$actions .= "\t\t\t\t\$this->flash(__('Invalid {$currentModelName} id.', '/{$controllerPath}/index', true));\n"; $actions .= "\t\t\t\t\$this->flash('Invalid id for {$singularHumanName}', '{$admin_url}/{$controllerPath}/index');\n";
} }
$actions .= "\t\t\t}\n"; $actions .= "\t\t\t}\n";
$actions .= "\t\t\t\$this->data = \$this->{$currentModelName}->read(null, \$id);\n"; $actions .= "\t\t\t\$this->data = \$this->{$currentModelName}->read(null, \$id);\n";
@ -1427,14 +1433,14 @@ class Bake {
$actions .= "\t\t\t\$this->cleanUpFields();\n"; $actions .= "\t\t\t\$this->cleanUpFields();\n";
$actions .= "\t\t\tif(\$this->{$currentModelName}->save(\$this->data)) {\n"; $actions .= "\t\t\tif(\$this->{$currentModelName}->save(\$this->data)) {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('The ".Inflector::humanize($currentModelName)." has been saved', true));\n"; $actions .= "\t\t\t\t\$this->Session->setFlash('The ".Inflector::humanize($currentModelName)." has been saved');\n";
$actions .= "\t\t\t\t\$this->redirect('/{$controllerPath}/index');\n"; $actions .= "\t\t\t\t\$this->redirect('{$admin_url}/{$controllerPath}/index');\n";
} else { } else {
$actions .= "\t\t\t\t\$this->flash(__('{$currentModelName} saved.', '/{$controllerPath}/index', true));\n"; $actions .= "\t\t\t\t\$this->flash('{$currentModelName} saved.', '{$admin_url}/{$controllerPath}/index');\n";
} }
$actions .= "\t\t\t} else {\n"; $actions .= "\t\t\t} else {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\t\$this->Session->setFlash(__('Please correct errors below.', true));\n"; $actions .= "\t\t\t\t\$this->Session->setFlash('Please correct errors below.');\n";
} }
foreach($modelObj->hasAndBelongsToMany as $associationName => $relation) { foreach($modelObj->hasAndBelongsToMany as $associationName => $relation) {
@ -1467,18 +1473,18 @@ class Bake {
$actions .= "\tfunction {$admin}delete(\$id = null) {\n"; $actions .= "\tfunction {$admin}delete(\$id = null) {\n";
$actions .= "\t\tif(!\$id) {\n"; $actions .= "\t\tif(!\$id) {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\$this->Session->setFlash(__('Invalid ".Inflector::humanize($currentModelName)." id.', true));\n"; $actions .= "\t\t\t\$this->Session->setFlash('Invalid id for {$singularHumanName}');\n";
$actions .= "\t\t\t\$this->redirect('/{$controllerPath}/index');\n"; $actions .= "\t\t\t\$this->redirect('{$admin_url}/{$controllerPath}/index');\n";
} else { } else {
$actions .= "\t\t\t\$this->flash(__('Invalid {$currentModelName} id.', '/{$controllerPath}/index', true));\n"; $actions .= "\t\t\t\$this->flash('Invalid id for {$singularHumanName}', '{$admin_url}/{$controllerPath}/index');\n";
} }
$actions .= "\t\t}\n"; $actions .= "\t\t}\n";
$actions .= "\t\tif(\$this->{$currentModelName}->del(\$id)) {\n"; $actions .= "\t\tif(\$this->{$currentModelName}->del(\$id)) {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') { if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\$this->Session->setFlash(__('The ".$this->__singularHumanName($currentModelName)." deleted: id '.\$id.'', true));\n"; $actions .= "\t\t\t\$this->Session->setFlash('The ".$this->__singularHumanName($currentModelName)." deleted: id '.\$id.'');\n";
$actions .= "\t\t\t\$this->redirect('/{$controllerPath}/index');\n"; $actions .= "\t\t\t\$this->redirect('{$admin_url}/{$controllerPath}/index');\n";
} else { } else {
$actions .= "\t\t\t\$this->flash(__('{$currentModelName} deleted: id '.\$id.'.', '/{$controllerPath}/index', true));\n"; $actions .= "\t\t\t\$this->flash('{$currentModelName} deleted: id '.\$id.'.', '{$admin_url}/{$controllerPath}/index');\n";
} }
$actions .= "\t\t}\n"; $actions .= "\t\t}\n";
$actions .= "\t}\n"; $actions .= "\t}\n";
@ -1831,9 +1837,9 @@ class Bake {
*/ */
function stdout($string, $newline = true) { function stdout($string, $newline = true) {
if ($newline) { if ($newline) {
fwrite($this->stdout, __($string . "\n", true)); fwrite($this->stdout, $string . "\n");
} else { } else {
fwrite($this->stdout, __($string)); fwrite($this->stdout, $string);
} }
} }
/** /**
@ -1866,17 +1872,17 @@ class Bake {
echo "\nCreating file $shortPath\n"; echo "\nCreating file $shortPath\n";
$path = str_replace('//', '/', $path); $path = str_replace('//', '/', $path);
if (is_file($path) && $this->interactive === true) { if (is_file($path) && $this->interactive === true) {
fwrite($this->stdout, __("File {$shortPath} exists, overwrite? (y/n/q):", true)); fwrite($this->stdout, "File {$shortPath} exists, overwrite? (y/n/q):");
$key = trim(fgets($this->stdin)); $key = trim(fgets($this->stdin));
if ($key=='q') { if ($key=='q') {
fwrite($this->stdout, __("Quitting.\n", true)); fwrite($this->stdout, "Quitting.\n");
exit; exit;
} elseif ($key == 'a') { } elseif ($key == 'a') {
$this->dont_ask = true; $this->dont_ask = true;
} elseif ($key == 'y') { } elseif ($key == 'y') {
} else { } else {
fwrite($this->stdout, __("Skip {$shortPath}\n", true)); fwrite($this->stdout, "Skip {$shortPath}\n");
return false; return false;
} }
} }
@ -1884,10 +1890,10 @@ class Bake {
if ($f = fopen($path, 'w')) { if ($f = fopen($path, 'w')) {
fwrite($f, $contents); fwrite($f, $contents);
fclose($f); fclose($f);
fwrite($this->stdout, __("Wrote {$shortPath}\n", true)); fwrite($this->stdout, "Wrote {$shortPath}\n");
return true; return true;
} else { } else {
fwrite($this->stderr, __("Error! Couldn't open {$shortPath} for writing.\n", true)); fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n");
return false; return false;
} }
} }
@ -2628,4 +2634,4 @@ class Bake {
} }
} }
?> ?>