fixing #1598: bake edit actions

fixing  baked views with admin

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3762 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2006-10-28 20:15:41 +00:00
parent 802ec2d913
commit b68181311c

View file

@ -836,6 +836,45 @@ class Bake {
die();
} else {
loadController($controllerName);
loadModels();
if($admin) {
$this->__bakeViews($controllerName, $controllerPath, $admin, $admin_url);
}
$this->__bakeViews($controllerName, $controllerPath, null, null);
$this->hr();
$this->stdout('');
$this->stdout('View Scaffolding Complete.'."\n");
}
} else {
$actionName = '';
while ($actionName == '') {
$actionName = $this->getInput('Action Name? (use camelCased function name)');
if ($actionName == '') {
$this->stdout('The action name you supplied was empty. Please try again.');
}
}
$this->stdout('');
$this->hr();
$this->stdout('The following view will be created:');
$this->hr();
$this->stdout("Controller Name: $controllerName");
$this->stdout("Action Name: $actionName");
$this->stdout("Path: app/views/" . $controllerPath . DS . Inflector::underscore($actionName) . '.thtml');
$this->hr();
$looksGood = $this->getInput('Look okay?', array('y','n'), 'y');
if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') {
$this->bakeView($controllerName, $actionName);
} else {
$this->stdout('Bake Aborted.');
}
}
}
function __bakeViews($controllerName, $controllerPath, $admin= null, $admin_url = null) {
$controllerClassName = $controllerName.'Controller';
$controllerObj = & new $controllerClassName();
@ -846,7 +885,6 @@ class Bake {
$controllerObj->helpers[] = 'Form';
}
loadModels();
$controllerObj->constructClasses();
$currentModelName = $controllerObj->modelClass;
$this->__modelClass = $currentModelName;
@ -1070,10 +1108,10 @@ class Bake {
$editView .= "</ul>\n";
//------------------------------------------------------------------------------------//
if(!file_exists(VIEWS.$controllerPath)) {
mkdir(VIEWS.$controllerPath);
}
if($admin) {
$filename = VIEWS . $controllerPath . DS . $admin . 'index.thtml';
$this->createFile($filename, $indexView);
$filename = VIEWS . $controllerPath . DS . $admin . 'view.thtml';
@ -1083,46 +1121,6 @@ class Bake {
$filename = VIEWS . $controllerPath . DS . $admin . 'edit.thtml';
$this->createFile($filename, $editView);
}
$filename = VIEWS . $controllerPath . DS . 'index.thtml';
$this->createFile($filename, $indexView);
$filename = VIEWS . $controllerPath . DS . 'view.thtml';
$this->createFile($filename, $viewView);
$filename = VIEWS . $controllerPath . DS . 'add.thtml';
$this->createFile($filename, $addView);
$filename = VIEWS . $controllerPath . DS . 'edit.thtml';
$this->createFile($filename, $editView);
$this->hr();
$this->stdout('');
$this->stdout('View Scaffolding Complete.'."\n");
}
} else {
$actionName = '';
while ($actionName == '') {
$actionName = $this->getInput('Action Name? (use camelCased function name)');
if ($actionName == '') {
$this->stdout('The action name you supplied was empty. Please try again.');
}
}
$this->stdout('');
$this->hr();
$this->stdout('The following view will be created:');
$this->hr();
$this->stdout("Controller Name: $controllerName");
$this->stdout("Action Name: $actionName");
$this->stdout("Path: app/views/" . $controllerPath . DS . Inflector::underscore($actionName) . '.thtml');
$this->hr();
$looksGood = $this->getInput('Look okay?', array('y','n'), 'y');
if (strtolower($looksGood) == 'y' || strtolower($looksGood) == 'yes') {
$this->bakeView($controllerName, $actionName);
} else {
$this->stdout('Bake Aborted.');
}
}
}
/**
* Action to create a Controller.
*
@ -1324,7 +1322,7 @@ class Bake {
$actions .= "\t\t\$this->set('".$singularName."', \$this->{$currentModelName}->read(null, \$id));\n";
$actions .= "\t}\n";
$actions .= "\n";
/* ADD ACTION */
$actions .= "\tfunction {$admin}add() {\n";
$actions .= "\t\tif(empty(\$this->data)) {\n";
@ -1355,7 +1353,7 @@ class Bake {
$actions .= "\t\t\t\$this->cleanUpFields();\n";
$actions .= "\t\t\tif(\$this->{$currentModelName}->save(\$this->data)) {\n";
if (strtolower($wannaUseSession) == 'y' || strtolower($wannaUseSession) == 'yes') {
$actions .= "\t\t\t\t\$this->Session->setFlash('The ".Inflector::humanize($currentModelName)." has been saved');\n";
$actions .= "\t\t\t\t\$this->Session->setFlash('The ".$this->__singularHumanName($currentModelName)." has been saved');\n";
$actions .= "\t\t\t\t\$this->redirect('{$admin_url}/{$controllerPath}/index');\n";
} else {
$actions .= "\t\t\t\t\$this->flash('{$currentModelName} saved.', '{$admin_url}/{$controllerPath}/index');\n";
@ -1392,7 +1390,7 @@ class Bake {
$actions .= "\t\t}\n";
$actions .= "\t}\n";
$actions .= "\n";
//EDIT FORM
/* EDIT ACTION */
$actions .= "\tfunction {$admin}edit(\$id = null) {\n";
$actions .= "\t\tif(empty(\$this->data)) {\n";
$actions .= "\t\t\tif(!\$id) {\n";
@ -1413,8 +1411,8 @@ class Bake {
$otherModelKey = Inflector::underscore($otherModelName);
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
$actions .= "\t\t\t\$this->set('{$otherPluralName}', \$this->{$currentModelName}->{$otherModelName}->generateList());\n";
$actions .= "\t\t\tif(empty(\$this->data['{$associationName}']['{$associationName}'])) { \$this->data['{$associationName}']['{$associationName}'] = null; }\n";
$actions .= "\t\t\t\$this->set('selected_{$otherPluralName}', \$this->_selectedArray(\$this->data['{$associationName}']['{$associationName}']));\n";
$actions .= "\t\t\tif(empty(\$this->data['{$associationName}'])) { \$this->data['{$associationName}'] = null; }\n";
$actions .= "\t\t\t\$this->set('selected_{$otherPluralName}', \$this->_selectedArray(\$this->data['{$associationName}']));\n";
}
}
foreach($modelObj->belongsTo as $associationName => $relation) {
@ -1837,9 +1835,9 @@ class Bake {
*/
function stdout($string, $newline = true) {
if ($newline) {
fwrite($this->stdout, $string . "\n");
fwrite($this->stdout, __($string, true) . "\n");
} else {
fwrite($this->stdout, $string);
fwrite($this->stdout, __($string, true));
}
}
/**
@ -1848,7 +1846,7 @@ class Bake {
* @param string $string Error text to output.
*/
function stderr($string) {
fwrite($this->stderr, $string);
fwrite($this->stderr, __($string, true));
}
/**
* Outputs a series of minus characters to the standard output, acts as a visual separator.
@ -1872,17 +1870,17 @@ class Bake {
echo "\nCreating file $shortPath\n";
$path = str_replace('//', '/', $path);
if (is_file($path) && $this->interactive === true) {
fwrite($this->stdout, "File {$shortPath} exists, overwrite? (y/n/q):");
fwrite($this->stdout, __("File exists, overwrite?", true). " {$shortPath} (y/n/q):");
$key = trim(fgets($this->stdin));
if ($key=='q') {
fwrite($this->stdout, "Quitting.\n");
fwrite($this->stdout, __("Quitting.", true) ."\n");
exit;
} elseif ($key == 'a') {
$this->dont_ask = true;
} elseif ($key == 'y') {
} else {
fwrite($this->stdout, "Skip {$shortPath}\n");
fwrite($this->stdout, __("Skip", true) ." {$shortPath}\n");
return false;
}
}
@ -1890,10 +1888,10 @@ class Bake {
if ($f = fopen($path, 'w')) {
fwrite($f, $contents);
fclose($f);
fwrite($this->stdout, "Wrote {$shortPath}\n");
fwrite($this->stdout, __("Wrote", true) ."{$shortPath}\n");
return true;
} else {
fwrite($this->stderr, "Error! Couldn't open {$shortPath} for writing.\n");
fwrite($this->stderr, __("Error! Could not write to", true)." {$shortPath}.\n");
return false;
}
}