mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
updating view task and adding view task templates
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5237 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
1b8ad3927d
commit
7ab1cad783
4 changed files with 584 additions and 447 deletions
|
@ -32,92 +32,172 @@
|
||||||
* @package cake
|
* @package cake
|
||||||
* @subpackage cake.cake.console.libs.tasks
|
* @subpackage cake.cake.console.libs.tasks
|
||||||
*/
|
*/
|
||||||
class ViewTask extends BakeShell {
|
class ViewTask extends Shell {
|
||||||
|
/**
|
||||||
|
* Tasks to be loaded by this Task
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $tasks = array('Project', 'Controller');
|
||||||
|
/**
|
||||||
|
* name of the controller being used
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $controllerName = null;
|
||||||
|
/**
|
||||||
|
* path to controller to put views
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $controllerPath = null;
|
||||||
|
/**
|
||||||
|
* the template file to use
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
var $template = null;
|
||||||
|
/**
|
||||||
|
* Actions to use for scaffolding
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
var $scaffoldActions = array('index', 'view', 'add', 'edit');
|
||||||
|
/**
|
||||||
|
* Override initialize
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function initialize() {}
|
||||||
|
/**
|
||||||
|
* Execution method always used for tasks
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
function execute() {
|
function execute() {
|
||||||
if(empty($this->args)) {
|
if(empty($this->args)) {
|
||||||
$this->__interactive();
|
$this->__interactive();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if(isset($this->args[0]) == 1 && $this->args[0] == 'help') {
|
||||||
|
$this->help();
|
||||||
|
}
|
||||||
|
|
||||||
|
$controller = $action = $alias = null;
|
||||||
|
if(isset($this->args[0])) {
|
||||||
|
$this->controllerName = Inflector::camelize($this->args[0]);
|
||||||
|
$this->controllerPath = Inflector::underscore($this->controllerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($this->args[1])) {
|
||||||
|
$this->template = $this->args[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($this->args[2])) {
|
||||||
|
$action = $this->args[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$action) {
|
||||||
|
$action = $this->template;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(in_array($action, $this->scaffoldActions)) {
|
||||||
|
$this->bake($action, true);
|
||||||
|
} else if($action) {
|
||||||
|
$this->bake($action, true);
|
||||||
|
} else {
|
||||||
|
$vars = $this->__loadController();
|
||||||
|
if($vars) {
|
||||||
|
$protected = array( 'object', low($this->controllerName. 'Controller'), 'controller', 'appcontroller',
|
||||||
|
'tostring', 'requestaction', 'log', 'cakeerror', 'constructclasses', 'redirect', 'set', 'setaction',
|
||||||
|
'validate', 'validateerrors', 'render', 'referer', 'flash', 'flashout', 'generatefieldnames',
|
||||||
|
'postconditions', 'cleanupfields', 'beforefilter', 'beforerender', 'afterfilter', 'disablecache', 'paginate');
|
||||||
|
|
||||||
|
$vars = get_class_vars($this->controllerName . 'Controller');
|
||||||
|
if(array_key_exists('scaffold', $vars)) {
|
||||||
|
$methods = $this->scaffoldActions;
|
||||||
|
} else {
|
||||||
|
$methods = get_class_methods($this->controllerName . 'Controller');
|
||||||
|
}
|
||||||
|
foreach($methods as $method) {
|
||||||
|
if($method{0} != '_' && !in_array(low($method), $protected)) {
|
||||||
|
$content = $this->getContent($method, $vars);
|
||||||
|
$this->bake($method, $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Handles interactive baking
|
||||||
|
*
|
||||||
|
* @access private
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
function __interactive() {
|
function __interactive() {
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->out('View Bake:');
|
$this->out('View Bake:');
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$uses = array();
|
$wannaDoAdmin = 'n';
|
||||||
$wannaUseSession = 'y';
|
|
||||||
$wannaDoScaffold = 'y';
|
$wannaDoScaffold = 'y';
|
||||||
|
|
||||||
$controllerName = $this->__getControllerName();
|
$this->controllerName = $this->Controller->getName();
|
||||||
$controllerPath = low(Inflector::underscore($controllerName));
|
|
||||||
|
|
||||||
$doItInteractive = $this->in("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite {$controllerName} views if it exist.", array('y','n'), 'y');
|
$this->controllerPath = low(Inflector::underscore($this->controllerName));
|
||||||
|
|
||||||
if (low($doItInteractive) == 'y' || low($doItInteractive) == 'yes') {
|
$interactive = $this->in("Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite {$this->controllerName} views if it exist.", array('y','n'), 'y');
|
||||||
$this->interactive = true;
|
|
||||||
|
if (low($interactive) == 'y' || low($interactive) == 'yes') {
|
||||||
$wannaDoScaffold = $this->in("Would you like to create some scaffolded views (index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller and model classes (including associated models).", array('y','n'), 'n');
|
$wannaDoScaffold = $this->in("Would you like to create some scaffolded views (index, add, view, edit) for this controller?\nNOTE: Before doing so, you'll need to create your controller and model classes (including associated models).", array('y','n'), 'n');
|
||||||
}
|
}
|
||||||
|
|
||||||
$admin = null;
|
|
||||||
$admin_url = null;
|
|
||||||
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
||||||
$wannaDoAdmin = $this->in("Would you like to create the views for admin routing?", array('y','n'), 'y');
|
$wannaDoAdmin = $this->in("Would you like to create the views for admin routing?", array('y','n'), 'y');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$admin = '';
|
||||||
if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
|
if ((low($wannaDoAdmin) == 'y' || low($wannaDoAdmin) == 'yes')) {
|
||||||
if(defined('CAKE_ADMIN')) {
|
if(defined('CAKE_ADMIN')) {
|
||||||
$admin = CAKE_ADMIN . '_';
|
$admin = CAKE_ADMIN . '_';
|
||||||
$admin_url = '/'.CAKE_ADMIN;
|
|
||||||
} else {
|
} else {
|
||||||
$adminRoute = '';
|
|
||||||
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
||||||
$this->out('What would you like the admin route to be?');
|
$this->out('What would you like the admin route to be?');
|
||||||
$this->out('Example: www.example.com/admin/controller');
|
$this->out('Example: www.example.com/admin/controller');
|
||||||
while ($adminRoute == '') {
|
while ($admin == '') {
|
||||||
$adminRoute = $this->in("What would you like the admin route to be?", null, 'admin');
|
$admin = $this->in("What would you like the admin route to be?", null, 'admin');
|
||||||
}
|
}
|
||||||
if($this->__addAdminRoute($adminRoute) !== true){
|
if($this->Project->cakeAdmin($admin) !== true){
|
||||||
$this->out('Unable to write to /app/config/core.php.');
|
$this->err('Unable to write to /app/config/core.php.');
|
||||||
$this->out('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
$this->err('You need to enable CAKE_ADMIN in /app/config/core.php to use admin routing.');
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} else {
|
||||||
$admin = $adminRoute . '_';
|
$admin = $admin . '_';
|
||||||
$admin_url = '/'.$adminRoute;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
if (low($wannaDoScaffold) == 'y' || low($wannaDoScaffold) == 'yes') {
|
||||||
$file = CONTROLLERS . $controllerPath . '_controller.php';
|
$file = CONTROLLERS . $this->controllerPath . '_controller.php';
|
||||||
|
|
||||||
if(!file_exists($file)) {
|
if($admin) {
|
||||||
$shortPath = str_replace(ROOT, null, $file);
|
foreach($this->scaffoldActions as $action) {
|
||||||
$shortPath = str_replace('../', '', $shortPath);
|
$this->scaffoldActions[] = $admin . $action;
|
||||||
$shortPath = str_replace('//', '/', $shortPath);
|
|
||||||
$this->out('');
|
|
||||||
$this->out("The file '$shortPath' could not be found.\nIn order to scaffold, you'll need to first create the controller. ");
|
|
||||||
$this->out('');
|
|
||||||
die();
|
|
||||||
} else {
|
|
||||||
uses('controller'.DS.'controller');
|
|
||||||
loadController($controllerName);
|
|
||||||
//loadModels();
|
|
||||||
if($admin) {
|
|
||||||
$this->__bake($controllerName, $controllerPath, $admin, $admin_url);
|
|
||||||
}
|
}
|
||||||
$this->__bake($controllerName, $controllerPath, null, null);
|
|
||||||
|
|
||||||
$this->hr();
|
|
||||||
$this->out('');
|
|
||||||
$this->out('View Scaffolding Complete.'."\n");
|
|
||||||
}
|
}
|
||||||
|
$vars = $this->__loadController();
|
||||||
|
if($vars) {
|
||||||
|
foreach($this->scaffoldActions as $action) {
|
||||||
|
$content = $this->getContent($action, $vars);
|
||||||
|
$this->bake($action, $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->hr();
|
||||||
|
$this->out('');
|
||||||
|
$this->out('View Scaffolding Complete.'."\n");
|
||||||
} else {
|
} else {
|
||||||
$actionName = '';
|
$action = '';
|
||||||
|
while ($action == '') {
|
||||||
while ($actionName == '') {
|
$action = $this->in('Action Name? (use camelCased function name)');
|
||||||
$actionName = $this->in('Action Name? (use camelCased function name)');
|
if ($action == '') {
|
||||||
|
|
||||||
if ($actionName == '') {
|
|
||||||
$this->out('The action name you supplied was empty. Please try again.');
|
$this->out('The action name you supplied was empty. Please try again.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,430 +205,137 @@ class ViewTask extends BakeShell {
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->out('The following view will be created:');
|
$this->out('The following view will be created:');
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$this->out("Controller Name: $controllerName");
|
$this->out("Controller Name: {$this->controllerName}");
|
||||||
$this->out("Action Name: $actionName");
|
$this->out("Action Name: {$action}");
|
||||||
$this->out("Path: app/views/" . $controllerPath . DS . Inflector::underscore($actionName) . '.ctp');
|
$this->out("Path: ".$this->params['app'] . DS . $this->controllerPath . DS . Inflector::underscore($action) . ".ctp");
|
||||||
$this->hr();
|
$this->hr();
|
||||||
$looksGood = $this->in('Look okay?', array('y','n'), 'y');
|
$looksGood = $this->in('Look okay?', array('y','n'), 'y');
|
||||||
|
|
||||||
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
||||||
$this->__bakeView($controllerName, $actionName);
|
$this->bake($action);
|
||||||
|
exit();
|
||||||
} else {
|
} else {
|
||||||
$this->out('Bake Aborted.');
|
$this->out('Bake Aborted.');
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function __bake($controllerName, $controllerPath, $admin= null, $admin_url = null) {
|
|
||||||
$controllerClassName = $controllerName.'Controller';
|
|
||||||
$controllerObj = & new $controllerClassName();
|
|
||||||
|
|
||||||
if(!in_array('Html', $controllerObj->helpers)) {
|
|
||||||
$controllerObj->helpers[] = 'Html';
|
|
||||||
}
|
|
||||||
if(!in_array('Form', $controllerObj->helpers)) {
|
|
||||||
$controllerObj->helpers[] = 'Form';
|
|
||||||
}
|
|
||||||
|
|
||||||
$controllerObj->constructClasses();
|
|
||||||
$currentModelName = $controllerObj->modelClass;
|
|
||||||
$this->__modelClass = $currentModelName;
|
|
||||||
$modelKey = $controllerObj->modelKey;
|
|
||||||
$modelObj =& ClassRegistry::getObject($modelKey);
|
|
||||||
$singularName = $this->_singularName($currentModelName);
|
|
||||||
$pluralName = $this->_pluralName($currentModelName);
|
|
||||||
$singularHumanName = $this->_singularHumanName($currentModelName);
|
|
||||||
$pluralHumanName = $this->_pluralHumanName($controllerName);
|
|
||||||
|
|
||||||
$fieldNames = $controllerObj->generateFieldNames(null, false);
|
|
||||||
|
|
||||||
//-------------------------[INDEX]-------------------------//
|
|
||||||
$indexView = null;
|
|
||||||
$indexView .= "<div class=\"{$pluralName}\">\n";
|
|
||||||
$indexView .= "<h2>List " . $pluralHumanName . "</h2>\n\n";
|
|
||||||
$indexView .= "<table cellpadding=\"0\" cellspacing=\"0\">\n";
|
|
||||||
$indexView .= "\t<tr>\n";
|
|
||||||
foreach ($fieldNames as $fieldName) {
|
|
||||||
$indexView .= "\t\t<th><?php echo \$paginator->sort('{$fieldName['name']}');?></th>\n";
|
|
||||||
}
|
|
||||||
$indexView .= "\t\t<th>Actions</th>\n";
|
|
||||||
$indexView .= "\t</tr>\n";
|
|
||||||
$indexView .= "<?php foreach (\${$pluralName} as \${$singularName}): ?>\n";
|
|
||||||
$indexView .= "\t<tr>\n";
|
|
||||||
$count = 0;
|
|
||||||
foreach($fieldNames as $field => $value) {
|
|
||||||
if(isset($value['foreignKey'])) {
|
|
||||||
$otherModelName = $this->_modelName($value['model']);
|
|
||||||
$otherModelKey = Inflector::underscore($value['modelKey']);
|
|
||||||
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
|
||||||
$otherControllerName = $this->_controllerName($value['modelKey']);
|
|
||||||
$otherControllerPath = $this->_controllerPath($otherControllerName);
|
|
||||||
if(is_object($otherModelObj)) {
|
|
||||||
$displayField = $otherModelObj->getDisplayField();
|
|
||||||
$indexView .= "\t\t<td><?php echo \$html->link(\$".$singularName."['{$otherModelName}']['{$displayField}'], array('controller'=> '{$otherControllerPath}', 'action'=>'view', \$".$singularName."['{$otherModelName}']['{$otherModelObj->primaryKey}'])); ?></td>\n";
|
|
||||||
} else {
|
|
||||||
$indexView .= "\t\t<td><?php echo \$".$singularName."['{$modelObj->name}']['{$field}']; ?></td>\n";
|
|
||||||
}
|
|
||||||
$count++;
|
|
||||||
} else {
|
|
||||||
$indexView .= "\t\t<td><?php echo \$".$singularName."['{$modelObj->name}']['{$field}']; ?></td>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$indexView .= "\t\t<td class=\"actions\">\n";
|
|
||||||
$indexView .= "\t\t\t<?php echo \$html->link('View', array('action'=>'view', \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])); ?>\n";
|
|
||||||
$indexView .= "\t\t\t<?php echo \$html->link('Edit', array('action'=>'edit', \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])); ?>\n";
|
|
||||||
$indexView .= "\t\t\t<?php echo \$html->link('Delete', array('action'=>'delete', \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}']), null, 'Are you sure you want to delete #' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}']); ?>\n";
|
|
||||||
$indexView .= "\t\t</td>\n";
|
|
||||||
$indexView .= "\t</tr>\n";
|
|
||||||
$indexView .= "<?php endforeach; ?>\n";
|
|
||||||
$indexView .= "</table>\n\n";
|
|
||||||
$indexView .= "</div>\n";
|
|
||||||
$indexView .= "<div class=\"paging\">\n";
|
|
||||||
$indexView .= "<?php echo \$paginator->prev('<< previous', array(), null, array('class'=>'disabled'));?>\n";
|
|
||||||
$indexView .= "|\n";
|
|
||||||
$indexView .= "<?php echo \$paginator->next('next >>', array(), null, array('class'=>'disabled'));?>\n";
|
|
||||||
$indexView .= "</div>\n";
|
|
||||||
$indexView .= "<div class=\"actions\">\n";
|
|
||||||
$indexView .= "\t<ul>\n";
|
|
||||||
$indexView .= "\t\t<li><?php echo \$html->link('New {$singularHumanName}', array('action'=>'add')); ?></li>\n";
|
|
||||||
$indexView .= "\t</ul>\n";
|
|
||||||
$indexView .= "</div>";
|
|
||||||
|
|
||||||
//-------------------------[VIEW]-------------------------//
|
|
||||||
$viewView = null;
|
|
||||||
$viewView .= "<div class=\"{$singularName}\">\n";
|
|
||||||
$viewView .= "<h2>View " . $singularHumanName . "</h2>\n\n";
|
|
||||||
$viewView .= "\t<dl>\n";
|
|
||||||
$count = 0;
|
|
||||||
foreach($fieldNames as $field => $value) {
|
|
||||||
$viewView .= "\t\t<dt>" . $value['label'] . "</dt>\n";
|
|
||||||
if(isset($value['foreignKey'])) {
|
|
||||||
$otherModelName = $this->_modelName($value['model']);
|
|
||||||
$otherModelKey = Inflector::underscore($value['modelKey']);
|
|
||||||
$otherModelObj =& ClassRegistry::getObject($value['modelKey']);
|
|
||||||
$otherControllerName = $this->_controllerName($value['modelKey']);
|
|
||||||
$otherControllerPath = $this->_controllerPath($otherControllerName);
|
|
||||||
$displayField = $otherModelObj->getDisplayField();
|
|
||||||
$viewView .= "\t\t<dd> <?php echo \$html->link(\$".$singularName."['{$otherModelName}']['{$displayField}'], array('controller'=> '{$otherControllerPath}', 'action'=>'view', \$".$singularName."['{$otherModelName}']['{$otherModelObj->primaryKey}'])); ?></dd>\n";
|
|
||||||
$count++;
|
|
||||||
} else {
|
|
||||||
$viewView .= "\t\t<dd> <?php echo \$".$singularName."['{$modelObj->name}']['{$field}']?></dd>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$viewView .= "\t</dl>\n";
|
|
||||||
$viewView .= "</div>\n";
|
|
||||||
$viewView .= "<div class=\"actions\">\n";
|
|
||||||
$viewView .= "\t<ul>\n";
|
|
||||||
$viewView .= "\t\t<li><?php echo \$html->link('Edit " . $singularHumanName . "', array('action'=>'edit', \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'])); ?> </li>\n";
|
|
||||||
$viewView .= "\t\t<li><?php echo \$html->link('Delete " . $singularHumanName . "', array('action'=>'delete', \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}']), null, 'Are you sure you want to delete #' . \$".$singularName."['{$modelObj->name}']['{$modelObj->primaryKey}'] . '?'); ?> </li>\n";
|
|
||||||
$viewView .= "\t\t<li><?php echo \$html->link('List " . $pluralHumanName ."', array('action'=>'index')); ?> </li>\n";
|
|
||||||
$viewView .= "\t\t<li><?php echo \$html->link('New " . $singularHumanName . "', array('action'=>'add')); ?> </li>\n";
|
|
||||||
foreach( $fieldNames as $field => $value ) {
|
|
||||||
if( isset( $value['foreignKey'] ) ) {
|
|
||||||
$otherModelName = $this->_modelName($value['modelKey']);
|
|
||||||
if($otherModelName != $currentModelName) {
|
|
||||||
$otherControllerName = $this->_controllerName($otherModelName);
|
|
||||||
$otherControllerPath = $this->_controllerPath($otherControllerName);
|
|
||||||
$otherSingularHumanName = $this->_singularHumanName($value['controller']);
|
|
||||||
$otherPluralHumanName = $this->_pluralHumanName($value['controller']);
|
|
||||||
$viewView .= "\t\t<li><?php echo \$html->link('List " . $otherSingularHumanName . "', array('controller'=> '{$otherControllerPath}', 'action'=>'index')); ?> </li>\n";
|
|
||||||
$viewView .= "\t\t<li><?php echo \$html->link('New " . $otherPluralHumanName . "', array('controller'=> '{$otherControllerPath}', 'action'=>'add')); ?> </li>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$viewView .= "\t</ul>\n\n";
|
|
||||||
$viewView .= "</div>\n";
|
|
||||||
|
|
||||||
foreach ($modelObj->hasOne as $associationName => $relation) {
|
|
||||||
$new = true;
|
|
||||||
$otherModelName = $this->_modelName($relation['className']);
|
|
||||||
$otherControllerName = $this->_controllerName($otherModelName);
|
|
||||||
$otherControllerPath = $this->_controllerPath($otherControllerName);
|
|
||||||
$otherSingularName = $this->_singularName($associationName);
|
|
||||||
$otherPluralHumanName = $this->_pluralHumanName($associationName);
|
|
||||||
$otherSingularHumanName = $this->_singularHumanName($associationName);
|
|
||||||
$otherModelKey = Inflector::underscore($relation['className']);
|
|
||||||
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
|
||||||
|
|
||||||
$viewView .= "<div class=\"related\">\n";
|
|
||||||
$viewView .= "<h3>Related " . $otherPluralHumanName . "</h3>\n";
|
|
||||||
$viewView .= "<?php if(!empty(\${$singularName}['{$associationName}'])): ?>\n";
|
|
||||||
$viewView .= "\t<dl>\n";
|
|
||||||
foreach($otherModelObj->_tableInfo->value as $column) {
|
|
||||||
$viewView .= "\t\t<dt>".Inflector::humanize($column['name'])."</dt>\n";
|
|
||||||
$viewView .= "\t\t<dd> <?php echo \${$singularName}['{$associationName}']['{$column['name']}'] ?></dd>\n";
|
|
||||||
}
|
|
||||||
$viewView .= "\t</dl>\n";
|
|
||||||
$viewView .= "<?php endif; ?>\n";
|
|
||||||
$viewView .= "\t<div class=\"actions\">\n";
|
|
||||||
$viewView .= "\t\t<ul>\n";
|
|
||||||
$viewView .= "\t\t\t<li><?php echo \$html->link('Edit " . $otherSingularHumanName . "', array('controller'=> '{$otherControllerPath}', 'action'=>'edit', \$".$singularName."['{$associationName}']['" . $modelObj->{$otherModelName}->primaryKey . "']));?></li>\n";
|
|
||||||
$viewView .= "\t\t</ul>\n";
|
|
||||||
$viewView .= "\t</div>\n";
|
|
||||||
$viewView .= "</div>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$relations = array_merge($modelObj->hasMany, $modelObj->hasAndBelongsToMany);
|
|
||||||
foreach($relations as $associationName => $relation) {
|
|
||||||
$otherModelName = $associationName;
|
|
||||||
$otherControllerName = $this->_controllerName($relation['className']);
|
|
||||||
$otherControllerPath = $this->_controllerPath($otherControllerName);
|
|
||||||
$otherSingularName = $this->_singularName($associationName);
|
|
||||||
$otherPluralHumanName = $this->_pluralHumanName($associationName);
|
|
||||||
$otherSingularHumanName = $this->_singularHumanName($associationName);
|
|
||||||
$otherModelKey = Inflector::underscore($relation['className']);
|
|
||||||
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
|
||||||
|
|
||||||
$viewView .= "<div class=\"related\">\n";
|
|
||||||
$viewView .= "<h3>Related " . $otherPluralHumanName . "</h3>\n";
|
|
||||||
$viewView .= "<?php if(!empty(\${$singularName}['{$associationName}'])):?>\n";
|
|
||||||
$viewView .= "<table cellpadding=\"0\" cellspacing=\"0\">\n";
|
|
||||||
$viewView .= "\t<tr>\n";
|
|
||||||
foreach($otherModelObj->_tableInfo->value as $column) {
|
|
||||||
$viewView .= "\t\t<th>".Inflector::humanize($column['name'])."</th>\n";
|
|
||||||
}
|
|
||||||
$viewView .= "\t\t<th>Actions</th>\n";
|
|
||||||
$viewView .= "\t</tr>\n";
|
|
||||||
$viewView .= "<?php foreach(\${$singularName}['{$associationName}'] as \$".$otherSingularName."):?>\n";
|
|
||||||
$viewView .= "\t<tr>\n";
|
|
||||||
foreach($otherModelObj->_tableInfo->value as $column) {
|
|
||||||
$viewView .= "\t\t<td><?php echo \${$otherSingularName}['{$column['name']}'];?></td>\n";
|
|
||||||
}
|
|
||||||
$viewView .= "\t\t<td class=\"actions\">\n";
|
|
||||||
$viewView .= "\t\t\t<?php echo \$html->link('View', array('controller'=> '{$otherControllerPath}', 'action'=>'view', \$".$otherSingularName."['{$otherModelObj->primaryKey}'])); ?>\n";
|
|
||||||
$viewView .= "\t\t\t<?php echo \$html->link('Edit', array('controller'=> '{$otherControllerPath}', 'action'=>'edit', \$".$otherSingularName."['{$otherModelObj->primaryKey}'])); ?>\n";
|
|
||||||
$viewView .= "\t\t\t<?php echo \$html->link('Delete', array('controller'=> '{$otherControllerPath}', 'action'=>'delete', \$".$otherSingularName."['{$otherModelObj->primaryKey}']), null, 'Are you sure you want to delete #' . \$".$otherSingularName."['{$otherModelObj->primaryKey}'] . '?'); ?>\n";
|
|
||||||
$viewView .= "\t\t</td>\n";
|
|
||||||
$viewView .= "\t</tr>\n";
|
|
||||||
$viewView .= "<?php endforeach; ?>\n";
|
|
||||||
$viewView .= "</table>\n";
|
|
||||||
$viewView .= "<?php endif; ?>\n\n";
|
|
||||||
$viewView .= "\t<div class=\"actions\">\n";
|
|
||||||
$viewView .= "\t\t<ul>\n";
|
|
||||||
$viewView .= "\t\t\t<li><?php echo \$html->link('New " . $otherSingularHumanName . "', array('controller'=> '{$otherControllerPath}', 'action'=>'add'));?> </li>\n";
|
|
||||||
$viewView .= "\t\t</ul>\n";
|
|
||||||
$viewView .= "\t</div>\n";
|
|
||||||
$viewView .= "</div>\n";
|
|
||||||
}
|
|
||||||
$fields = $controllerObj->generateFieldNames(null, true);
|
|
||||||
//-------------------------[EDIT]-------------------------//
|
|
||||||
$editView = null;
|
|
||||||
$editView .= "<div class=\"".$singularName."\">\n";
|
|
||||||
$editView .= "<h2>Edit " . $singularHumanName . "</h2>\n";
|
|
||||||
$editView .= "\t<?php echo \$form->create('{$currentModelName}');?>\n";
|
|
||||||
$editView .= $this->inputs($fields);
|
|
||||||
$editView .= "\t\t<?php echo \$form->submit('Update');?>\n";
|
|
||||||
$editView .= "\t</form>\n";
|
|
||||||
$editView .= "</div>\n";
|
|
||||||
$editView .= "<div class=\"actions\">\n";
|
|
||||||
$editView .= "\t<ul>\n";
|
|
||||||
$editView .= "\t\t<li><?php echo \$html->link('Delete', array('action'=>'delete', \$html->tagValue('{$modelObj->name}/{$modelObj->primaryKey}')), null, 'Are you sure you want to delete #' . \$html->tagValue('{$modelObj->name}/{$modelObj->primaryKey}')); ?>\n";
|
|
||||||
$editView .= "\t\t<li><?php echo \$html->link('List {$pluralHumanName}', array('action'=>'index')); ?></li>\n";
|
|
||||||
foreach ($modelObj->belongsTo as $associationName => $relation) {
|
|
||||||
$otherModelName = $this->_modelName($relation['className']);
|
|
||||||
if($otherModelName != $currentModelName) {
|
|
||||||
$otherControllerName = $this->_controllerName($otherModelName);
|
|
||||||
$otherControllerPath = $this->_controllerPath($otherControllerName);
|
|
||||||
$otherSingularName = $this->_singularName($associationName);
|
|
||||||
$otherPluralName = $this->_pluralHumanName($associationName);
|
|
||||||
$editView .= "\t\t<li><?php echo \$html->link('View " . $otherPluralName . "', array('controller'=> '{$otherControllerPath}', 'action'=>'view')); ?></li>\n";
|
|
||||||
$editView .= "\t\t<li><?php echo \$html->link('Add " . $otherPluralName . "', array('controller'=> '{$otherControllerPath}', 'action'=>'add')); ?></li>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$editView .= "\t</ul>\n";
|
|
||||||
$editView .= "</div>\n";
|
|
||||||
//-------------------------[ADD]-------------------------//
|
|
||||||
unset($fields[$modelObj->primaryKey]);
|
|
||||||
$addView = null;
|
|
||||||
$addView .= "<div class=\"".low($singularName)."\">\n";
|
|
||||||
$addView .= "<h2>New " . $singularHumanName . "</h2>\n";
|
|
||||||
$addView .= "\t<?php echo \$form->create('{$currentModelName}');?>\n";
|
|
||||||
$addView .= $this->inputs($fields);
|
|
||||||
$addView .= "\t\t<?php echo \$form->submit('Add');?>\n";
|
|
||||||
$addView .= "\t</form>\n";
|
|
||||||
$addView .= "</div>\n";
|
|
||||||
$addView .= "<div class=\"actions\">\n";
|
|
||||||
$addView .= "\t<ul>\n";
|
|
||||||
$addView .= "\t\t<li><?php echo \$html->link('List {$pluralHumanName}', array('action'=>'index')); ?></li>\n";
|
|
||||||
foreach ($modelObj->belongsTo as $associationName => $relation) {
|
|
||||||
$otherModelName = $this->_modelName($relation['className']);
|
|
||||||
if($otherModelName != $currentModelName) {
|
|
||||||
$otherControllerName = $this->_controllerName($otherModelName);
|
|
||||||
$otherControllerPath = $this->_controllerPath($otherControllerName);
|
|
||||||
$otherSingularName = $this->_singularName($associationName);
|
|
||||||
$otherPluralName = $this->_pluralHumanName($associationName);
|
|
||||||
$addView .= "\t\t<li><?php echo \$html->link('View " . $otherPluralName . "', array('controller'=> '{$otherControllerPath}', 'action'=>'view'));?></li>\n";
|
|
||||||
$addView .= "\t\t<li><?php echo \$html->link('Add " . $otherPluralName . "', array('controller'=> '{$otherControllerPath}', 'action'=>'add')); ?></li>\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$addView .= "\t</ul>\n";
|
|
||||||
$addView .= "</div>\n";
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------//
|
|
||||||
|
|
||||||
$Folder =& new Folder(VIEWS . $controllerPath, true);
|
|
||||||
if($path = $Folder->cd(VIEWS . $controllerPath)) {
|
|
||||||
$path = $Folder->slashTerm(VIEWS . $controllerPath);
|
|
||||||
$filename = $path . $admin . 'index.ctp';
|
|
||||||
$this->createFile($filename, $indexView);
|
|
||||||
$filename = $path . $admin . 'view.ctp';
|
|
||||||
$this->createFile($filename, $viewView);
|
|
||||||
$filename = $path . $admin . 'add.ctp';
|
|
||||||
$this->createFile($filename, $addView);
|
|
||||||
$filename = $path . $admin . 'edit.ctp';
|
|
||||||
$this->createFile($filename, $editView);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assembles and writes a View file.
|
* Loads Controller and sets variables for the template
|
||||||
*
|
* Available template variables
|
||||||
* @param string $controllerName
|
* 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
|
||||||
* @param string $actionName
|
* 'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys',
|
||||||
* @param string $content
|
* 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'
|
||||||
*/
|
|
||||||
function __bakeView($controllerName, $actionName, $content = '') {
|
|
||||||
$out = "<h2>{$actionName}</h2>\n";
|
|
||||||
$out .= $content;
|
|
||||||
if(!file_exists(VIEWS.$this->_controllerPath($controllerName))) {
|
|
||||||
mkdir(VIEWS.$this->_controllerPath($controllerName));
|
|
||||||
}
|
|
||||||
$filename = VIEWS . $this->_controllerPath($controllerName) . DS . Inflector::underscore($actionName) . '.ctp';
|
|
||||||
$Folder =& new Folder(VIEWS . $controllerPath, true);
|
|
||||||
if($path = $Folder->cd(VIEWS . $controllerPath)) {
|
|
||||||
$path = $Folder->slashTerm(VIEWS . $controllerPath);
|
|
||||||
return $this->createFile($filename, $out);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns the fields to be display in the baked forms.
|
|
||||||
*
|
*
|
||||||
* @access private
|
* @access private
|
||||||
* @param array $fields
|
* @return array Returns an variables to be made available to a view template
|
||||||
*/
|
*/
|
||||||
function inputs($fields = array()) {
|
function __loadController() {
|
||||||
$displayFields = null;
|
if(!$this->controllerName) {
|
||||||
|
$this->err('could not find the controller');
|
||||||
foreach($fields as $name => $options) {
|
|
||||||
if(isset($options['tagName'])){
|
|
||||||
$tag = explode('/', $options['tagName']);
|
|
||||||
$tagName = $tag[1];
|
|
||||||
unset($options['tagName']);
|
|
||||||
}
|
|
||||||
$formOptions = array();
|
|
||||||
|
|
||||||
if(isset($options['type'])){
|
|
||||||
$type = $options['type'];
|
|
||||||
unset($options['type']);
|
|
||||||
//$formOptions['type'] = "'type' => '{$type}'";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($options['class']) && $options['class'] == 'required'){
|
|
||||||
$class = $options['class'];
|
|
||||||
unset($options['class']);
|
|
||||||
$formOptions['class'] = "'class' => '{$class}'";
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($options['options'])){
|
|
||||||
unset($formOptions['type']);
|
|
||||||
$fieldOptions = $this->_pluralName($options['model']);
|
|
||||||
unset($options['options']);
|
|
||||||
$formOptions['options'] = "'options' => \${$fieldOptions}";
|
|
||||||
if(isset($options['multiple'])){
|
|
||||||
$formOptions['multiple'] = "'multiple' => 'multiple'";
|
|
||||||
$tagName = $tagName.'/'.$tagName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(isset($options['size'])){
|
|
||||||
$size = $options['size'];
|
|
||||||
unset($options['size']);
|
|
||||||
//$formOptions['size'] = "'size' => '{$size}'";
|
|
||||||
}
|
|
||||||
if(isset($options['cols'])){
|
|
||||||
$cols = $options['cols'];
|
|
||||||
unset($options['cols']);
|
|
||||||
//$formOptions['cols'] = "'cols' => '{$cols}'";
|
|
||||||
}
|
|
||||||
if(isset($options['rows'])){
|
|
||||||
$rows = $options['rows'];
|
|
||||||
unset($options['rows']);
|
|
||||||
//$formOptions['rows'] = "'rows' => '{$rows}'";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(!empty($formOptions)) {
|
|
||||||
$formOptions = ", array(".join(', ', $formOptions).")";
|
|
||||||
} else {
|
|
||||||
$formOptions = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$displayFields .= "\t\t<?php echo \$form->input('{$tagName}'{$formOptions});?>\n";
|
|
||||||
}
|
}
|
||||||
return $displayFields;
|
|
||||||
|
if(!loadController($this->controllerName)) {
|
||||||
|
$file = CONTROLLERS . $this->controllerPath . '_controller.php';
|
||||||
|
$shortPath = $this->shortPath($file);
|
||||||
|
$this->err("The file '{$shortPath}' could not be found.\nIn order to bake a view, you'll need to first create the controller.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$controllerClassName = $this->controllerName . 'Controller';
|
||||||
|
$controllerObj = & new $controllerClassName();
|
||||||
|
$controllerObj->constructClasses();
|
||||||
|
$modelClass = $controllerObj->modelClass;
|
||||||
|
$modelKey = $controllerObj->modelKey;
|
||||||
|
$modelObj =& ClassRegistry::getObject($modelKey);
|
||||||
|
$primaryKey = $modelObj->primaryKey;
|
||||||
|
$displayField = $modelObj->displayField;
|
||||||
|
$singularVar = Inflector::variable($modelClass);
|
||||||
|
$pluralVar = Inflector::variable($this->controllerName);
|
||||||
|
$singularHumanName = Inflector::humanize($modelClass);
|
||||||
|
$pluralHumanName = Inflector::humanize($this->controllerName);
|
||||||
|
$fields = $modelObj->_tableInfo->value;
|
||||||
|
$foreignKeys = $modelObj->keyToTable;
|
||||||
|
$belongsTo = $modelObj->belongsTo;
|
||||||
|
$hasOne = $modelObj->hasOne;
|
||||||
|
$hasMany = $modelObj->hasMany;
|
||||||
|
$hasAndBelongsToMany = $modelObj->hasAndBelongsToMany;
|
||||||
|
|
||||||
|
return compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
|
||||||
|
'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys',
|
||||||
|
'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* outputs the a list of possible models or controllers from database
|
* Assembles and writes bakes the view file.
|
||||||
*
|
*
|
||||||
* @param string $useDbConfig
|
* @param string $action
|
||||||
* @param string $type = Models or Controllers
|
* @param string $content
|
||||||
* @return output
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function __doList($useDbConfig = 'default') {
|
function bake($action, $content = '') {
|
||||||
$db =& ConnectionManager::getDataSource($useDbConfig);
|
if($content === true) {
|
||||||
$usePrefix = empty($db->config['prefix']) ? '' : $db->config['prefix'];
|
$content = $this->getContent();
|
||||||
if ($usePrefix) {
|
}
|
||||||
$tables = array();
|
$filename = VIEWS . $this->controllerPath . DS . Inflector::underscore($action) . '.ctp';
|
||||||
foreach ($db->listSources() as $table) {
|
$Folder =& new Folder(VIEWS . $this->controllerPath, true);
|
||||||
if (!strncmp($table, $usePrefix, strlen($usePrefix))) {
|
$errors = $Folder->errors();
|
||||||
$tables[] = substr($table, strlen($usePrefix));
|
if(empty($errors)) {
|
||||||
}
|
$path = $Folder->slashTerm($Folder->pwd());
|
||||||
}
|
return $this->createFile($filename, $content);
|
||||||
} else {
|
} else {
|
||||||
$tables = $db->listSources();
|
foreach($errors as $error) {
|
||||||
}
|
$this->err($error);
|
||||||
$this->__tables = $tables;
|
}
|
||||||
$this->out('Possible Models 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 false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forces the user to specify the controller for which he wants to bake views, and returns the selected controller name.
|
* Builds content from template and variables
|
||||||
*
|
*
|
||||||
* @return the controller name
|
* @param string $template file to use
|
||||||
|
* @param array $vars passed for use in templates
|
||||||
|
* @return string content from template
|
||||||
*/
|
*/
|
||||||
function __getControllerName() {
|
function getContent($template = null, $vars = null) {
|
||||||
$useDbConfig = 'default';
|
if(!$template) {
|
||||||
$this->__doList($useDbConfig, 'Controllers');
|
$template = $this->template;
|
||||||
|
}
|
||||||
$enteredController = '';
|
$action = $template;
|
||||||
|
if(in_array($template, array('add', 'edit'))) {
|
||||||
while ($enteredController == '') {
|
$action = $template;
|
||||||
$enteredController = $this->in('Enter a number from the list above, or type in the name of another controller.');
|
$template = 'form';
|
||||||
|
}
|
||||||
if ($enteredController == '' || intval($enteredController) > count($this->_controllerNames)) {
|
$loaded = false;
|
||||||
$this->out('Error:');
|
foreach($this->Dispatch->shellPaths as $path) {
|
||||||
$this->out("The Controller name you supplied was empty, or the number \nyou selected was not an option. Please try again.");
|
$templatePath = $path . 'templates' . DS . 'views' . DS .Inflector::underscore($template).'.ctp';
|
||||||
$enteredController = '';
|
if (file_exists($templatePath) && is_file($templatePath)) {
|
||||||
|
$loaded = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(!$vars) {
|
||||||
if (intval($enteredController) > 0 && intval($enteredController) <= count($this->_controllerNames) ) {
|
$vars = $this->__loadController();
|
||||||
$controllerName = $this->_controllerNames[intval($enteredController) - 1];
|
|
||||||
} else {
|
|
||||||
$controllerName = Inflector::camelize($enteredController);
|
|
||||||
}
|
}
|
||||||
|
if($loaded) {
|
||||||
return $controllerName;
|
extract($vars);
|
||||||
|
ob_start();
|
||||||
|
ob_implicit_flush(0);
|
||||||
|
include($templatePath);
|
||||||
|
$content = ob_get_clean();
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->err('Template for '. $template .' could not be found');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Builds content from template and variables
|
||||||
|
*
|
||||||
|
* @param string $template file to use
|
||||||
|
* @param array $params passed from controller
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function help() {
|
||||||
|
$this->out('Help');
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
72
cake/console/libs/templates/views/form.ctp
Normal file
72
cake/console/libs/templates/views/form.ctp
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.console.libs.templates.views
|
||||||
|
* @since CakePHP(tm) v 0.10.0.1076
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<div class="<?php echo $singularVar;?>">;
|
||||||
|
<?php echo "<?php echo \$form->create('{$modelClass}');?>\n";?>
|
||||||
|
<fieldset>
|
||||||
|
<legend><?php echo Inflector::humanize($action).' '. $singularHumanName;?></legend>
|
||||||
|
<?php
|
||||||
|
echo "\t<?php\n";
|
||||||
|
foreach($fields as $field) {
|
||||||
|
if($action == 'add' && $field['name'] == $primaryKey) {
|
||||||
|
continue;
|
||||||
|
} else if(!in_array($field['name'], array('created', 'modified', 'updated'))){
|
||||||
|
echo "\t\techo \$form->input('{$field['name']}');\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach($hasAndBelongsToMany as $assocName => $assocData) {
|
||||||
|
echo "\t\techo \$form->input('{$assocName}.{$assocName}');\n";
|
||||||
|
}
|
||||||
|
echo "\t?>\n";
|
||||||
|
?>
|
||||||
|
</fieldset>
|
||||||
|
<?php
|
||||||
|
echo "<?php echo \$form->end('Submit');?>\n";
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<ul>
|
||||||
|
<?php if($action != 'add'):?>
|
||||||
|
<li><?php echo "<?php echo \$html->link('Delete', array('action'=>'delete', \$form->value('{$modelClass}.{$primaryKey}')), null, 'Are you sure you want to delete #' . \$form->value('{$modelClass}.{$primaryKey}')); ?>";?></li>
|
||||||
|
<?php endif;?>
|
||||||
|
<li><?php echo "<?php echo \$html->link('List {$pluralHumanName}', array('action'=>'index'));?>";?></li>
|
||||||
|
<?php
|
||||||
|
foreach($foreignKeys as $field => $value) {
|
||||||
|
$otherModelClass = $value['1'];
|
||||||
|
if($otherModelClass != $modelClass) {
|
||||||
|
$otherModelKey = Inflector::underscore($otherModelClass);
|
||||||
|
$otherControllerName = Inflector::pluralize($otherModelClass);
|
||||||
|
$otherControllerPath = Inflector::underscore($otherControllerName);
|
||||||
|
$otherSingularName = Inflector::variable($otherModelClass);
|
||||||
|
$otherPluralHumanName = Inflector::humanize($otherControllerPath);
|
||||||
|
$otherSingularHumanName = Inflector::humanize($otherModelKey);
|
||||||
|
echo "\t\t<li><?php echo \$html->link('List {$otherPluralHumanName}', array('controller'=> '{$otherControllerPath}', 'action'=>'index')); ?> </li>\n";
|
||||||
|
echo "\t\t<li><?php echo \$html->link('New {$otherSingularHumanName}', array('controller'=> '{$otherControllerPath}', 'action'=>'add')); ?> </li>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
99
cake/console/libs/templates/views/index.ctp
Normal file
99
cake/console/libs/templates/views/index.ctp
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.console.libs.templates.views
|
||||||
|
* @since CakePHP(tm) v 0.10.0.1076
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<div class="<?php echo $pluralVar;?>">
|
||||||
|
<h2>List <?php echo $pluralHumanName;?></h2>
|
||||||
|
<table cellpadding="0" cellspacing="0">
|
||||||
|
<tr>
|
||||||
|
<?php foreach($fields as $field):?>
|
||||||
|
<th><?php echo "<?php echo \$paginator->sort('{$field['name']}');?>";?></th>
|
||||||
|
<?php endforeach;?>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
echo "<?php
|
||||||
|
\$i = 0;
|
||||||
|
foreach(\${$pluralVar} as \${$singularVar}):
|
||||||
|
if(\$i++ % 2 == 0) {
|
||||||
|
\$class = ' class=\"altrow\"';
|
||||||
|
} else {
|
||||||
|
\$class = null;
|
||||||
|
}
|
||||||
|
?>\n";
|
||||||
|
echo "\t<tr<?php echo \$class;?>>\n";
|
||||||
|
|
||||||
|
foreach($fields as $field) {
|
||||||
|
if(in_array($field['name'], array_keys($foreignKeys))) {
|
||||||
|
$otherModelClass = $foreignKeys[$field['name']][1];
|
||||||
|
$otherModelKey = Inflector::underscore($otherModelClass);
|
||||||
|
$otherControllerName = Inflector::pluralize($otherModelClass);
|
||||||
|
$otherControllerPath = Inflector::underscore($otherControllerName);
|
||||||
|
$otherVariableName = Inflector::variable($otherModelClass);
|
||||||
|
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
||||||
|
$otherPrimaryKey = $otherModelObj->primaryKey;
|
||||||
|
$otherDisplayField = $otherModelObj->displayField;
|
||||||
|
echo "\t\t<td>\n\t\t\t<?php echo \$html->link(\${$singularVar}['{$otherModelClass}']['{$otherDisplayField}'], array('controller'=> '{$otherControllerPath}', 'action'=>'view', \${$singularVar}['{$otherModelClass}']['{$otherPrimaryKey}'])); ?>\n\t\t</td>\n";
|
||||||
|
} else {
|
||||||
|
echo "\t\t<td>\n\t\t\t<?php echo \${$singularVar}['{$modelClass}']['{$field['name']}']?>\n\t\t</td>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\t\t<td class=\"actions\">\n";
|
||||||
|
echo "\t\t\t<?php echo \$html->link('View', array('action'=>'view', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
|
||||||
|
echo "\t\t\t<?php echo \$html->link('Edit', array('action'=>'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
|
||||||
|
echo "\t\t\t<?php echo \$html->link('Delete', array('action'=>'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, 'Are you sure you want to delete #' . \${$singularVar}['{$modelClass}']['{$primaryKey}']); ?>\n";
|
||||||
|
echo "\t\t</td>\n";
|
||||||
|
echo "\t</tr>\n";
|
||||||
|
|
||||||
|
echo "<?php endforeach; ?>\n";
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="paging">
|
||||||
|
<?php echo "\t<?php echo \$paginator->prev('<< previous', array(), null, array('class'=>'disabled'));?>\n";?>
|
||||||
|
| <?php echo "\t<?php echo \$paginator->numbers();?>\n"?>
|
||||||
|
<?php echo "\t<?php echo \$paginator->next('next >>', array(), null, array('class'=>'disabled'));?>\n";?>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<ul>
|
||||||
|
<li><?php echo "<?php echo \$html->link('New {$singularHumanName}', array('action'=>'add')); ?>";?></li>
|
||||||
|
<?php
|
||||||
|
foreach($foreignKeys as $field => $value) {
|
||||||
|
$otherModelClass = $value['1'];
|
||||||
|
if($otherModelClass != $modelClass) {
|
||||||
|
$otherModelKey = Inflector::underscore($otherModelClass);
|
||||||
|
$otherControllerName = Inflector::pluralize($otherModelClass);
|
||||||
|
$otherControllerPath = Inflector::underscore($otherControllerName);
|
||||||
|
$otherVariableName = Inflector::variable($otherModelClass);
|
||||||
|
$otherPluralHumanName = Inflector::humanize($otherControllerPath);
|
||||||
|
$otherSingularHumanName = Inflector::humanize($otherModelKey);
|
||||||
|
echo "\t\t<li><?php echo \$html->link('List {$otherPluralHumanName}', array('controller'=> '{$otherControllerPath}', 'action'=>'index')); ?> </li>\n";
|
||||||
|
echo "\t\t<li><?php echo \$html->link('New {$otherSingularHumanName}', array('controller'=> '{$otherControllerPath}', 'action'=>'add')); ?> </li>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
179
cake/console/libs/templates/views/view.ctp
Normal file
179
cake/console/libs/templates/views/view.ctp
Normal file
|
@ -0,0 +1,179 @@
|
||||||
|
<?php
|
||||||
|
/* SVN FILE: $Id$ */
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PHP versions 4 and 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
||||||
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* 1785 E. Sahara Avenue, Suite 490-204
|
||||||
|
* Las Vegas, Nevada 89104
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @filesource
|
||||||
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
||||||
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.console.libs.templates.views
|
||||||
|
* @since CakePHP(tm) v 0.10.0.1076
|
||||||
|
* @version $Revision$
|
||||||
|
* @modifiedby $LastChangedBy$
|
||||||
|
* @lastmodified $Date$
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
|
*/
|
||||||
|
?>
|
||||||
|
<div class="<?php echo $singularVar;?>">
|
||||||
|
<h2>View <?php echo $singularHumanName;?></h2>
|
||||||
|
<dl>
|
||||||
|
<?php
|
||||||
|
$i = 0;
|
||||||
|
foreach($fields as $field) {
|
||||||
|
if($i++ % 2 == 0) {
|
||||||
|
$class = ' class="altrow"';
|
||||||
|
} else {
|
||||||
|
$class = null;
|
||||||
|
}
|
||||||
|
if(in_array($field['name'], array_keys($foreignKeys))) {
|
||||||
|
$otherModelClass = $foreignKeys[$field['name']][1];
|
||||||
|
$otherModelKey = Inflector::underscore($otherModelClass);
|
||||||
|
$otherControllerName = Inflector::pluralize($otherModelClass);
|
||||||
|
$otherControllerPath = Inflector::underscore($otherControllerName);
|
||||||
|
$otherSingularVar = Inflector::variable($otherModelClass);
|
||||||
|
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
||||||
|
$otherPrimaryKey = $otherModelObj->primaryKey;
|
||||||
|
$otherDisplayField = $otherModelObj->displayField;
|
||||||
|
echo "\t\t<dt{$class}>".Inflector::humanize($otherModelClass)."</dt>\n";
|
||||||
|
echo "\t\t<dd{$class}>\n\t\t\t<?php echo \$html->link(\${$singularVar}['{$otherModelClass}']['{$otherDisplayField}'], array('controller'=> '{$otherControllerPath}', 'action'=>'view', \${$singularVar}['{$otherModelClass}']['{$otherPrimaryKey}'])); ?>\n\t\t\t \n\t\t</dd>\n";
|
||||||
|
} else {
|
||||||
|
echo "\t\t<dt{$class}>".Inflector::humanize($field['name'])."</dt>\n";
|
||||||
|
echo "\t\t<dd{$class}>\n\t\t\t<?php echo \${$singularVar}['{$modelClass}']['{$field['name']}']?>\n\t\t\t \n\t\t</dd>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<ul>
|
||||||
|
<?php
|
||||||
|
echo "\t\t<li><?php echo \$html->link('Edit {$singularHumanName}', array('action'=>'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?> </li>\n";
|
||||||
|
echo "\t\t<li><?php echo \$html->link('Delete {$singularHumanName}', array('action'=>'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), null, 'Are you sure you want to delete #' . \${$singularVar}['{$modelClass}']['{$primaryKey}'] . '?'); ?> </li>\n";
|
||||||
|
echo "\t\t<li><?php echo \$html->link('List {$pluralHumanName}', array('action'=>'index')); ?> </li>\n";
|
||||||
|
echo "\t\t<li><?php echo \$html->link('New {$singularHumanName}', array('action'=>'add')); ?> </li>\n";
|
||||||
|
|
||||||
|
foreach($foreignKeys as $field => $value) {
|
||||||
|
$otherModelClass = $value['1'];
|
||||||
|
if($otherModelClass != $modelClass) {
|
||||||
|
$otherModelKey = Inflector::underscore($otherModelClass);
|
||||||
|
$otherControllerName = Inflector::pluralize($otherModelClass);
|
||||||
|
$otherControllerPath = Inflector::underscore($otherControllerName);
|
||||||
|
$otherSingularVar = Inflector::variable($otherModelClass);
|
||||||
|
$otherPluralHumanName = Inflector::humanize($otherControllerPath);
|
||||||
|
$otherSingularHumanName = Inflector::humanize($otherModelKey);
|
||||||
|
echo "\t\t<li><?php echo \$html->link('List {$otherPluralHumanName}', array('controller'=> '{$otherControllerPath}', 'action'=>'index')); ?> </li>\n";
|
||||||
|
echo "\t\t<li><?php echo \$html->link('New {$otherSingularHumanName}', array('controller'=> '{$otherControllerPath}', 'action'=>'add')); ?> </li>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
$i = 0;
|
||||||
|
foreach ($hasOne as $assocName => $assocData):
|
||||||
|
$otherModelKey = Inflector::underscore($assocData['className']);
|
||||||
|
$otherControllerPath = Inflector::pluralize($otherModelKey);
|
||||||
|
$otherControllerName = Inflector::camelize($otherControllerPath);
|
||||||
|
$assocKey = Inflector::underscore($assocName);
|
||||||
|
$otherPluralHumanName = Inflector::humanize(Inflector::pluralize($assocKey));
|
||||||
|
$otherSingularHumanName = Inflector::humanize($assocKey);
|
||||||
|
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
||||||
|
$otherFields = $otherModelObj->_tableInfo->value;
|
||||||
|
$otherPrimaryKey = $otherModelObj->primaryKey;
|
||||||
|
|
||||||
|
if($i++ % 2 == 0) {
|
||||||
|
$class = ' class="altrow"';
|
||||||
|
} else {
|
||||||
|
$class = null;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="related">
|
||||||
|
<h3>Related <?php echo $otherPluralHumanName;?></h3>
|
||||||
|
<?php echo "<?php if(!empty(\${$singularVar}['{$associationName}'])):?>\n";?>
|
||||||
|
<dl>
|
||||||
|
<?php
|
||||||
|
foreach($otherFields as $field) {
|
||||||
|
echo "\t\t<dt{$class}>".Inflector::humanize($field['name'])."</dt>\n";
|
||||||
|
echo "\t\t<dd{$class}>\n\t<?php echo \${$singularVar}['{$associationName}']['{$field['name']}'] ?>\n </dd>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</dl>
|
||||||
|
<?php echo "<?php endif; ?>\n";?>
|
||||||
|
<div class="actions">
|
||||||
|
<ul>
|
||||||
|
<li><?php echo "<?php echo \$html->link('Edit $otherSingularHumanName}', array('controller'=> '{$otherControllerPath}', 'action'=>'edit', \${$singularVar}['{$associationName}']['{$otherPrimaryKey}']));?></li>\n";?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$relations = array_merge($hasMany, $hasAndBelongsToMany);
|
||||||
|
$i = 0;
|
||||||
|
foreach($relations as $assocName => $assocData):
|
||||||
|
$otherModelKey = Inflector::underscore($assocData['className']);
|
||||||
|
$otherModelObj =& ClassRegistry::getObject($otherModelKey);
|
||||||
|
$otherControllerPath = Inflector::pluralize($otherModelKey);
|
||||||
|
$otherControllerName = Inflector::camelize($otherControllerPath);
|
||||||
|
$otherSingularVar = Inflector::variable($assocName);
|
||||||
|
$otherPluralHumanName = Inflector::humanize(Inflector::pluralize($assocName));
|
||||||
|
$otherSingularHumanName = Inflector::humanize($assocName);
|
||||||
|
$otherFields = $otherModelObj->_tableInfo->value;
|
||||||
|
$otherPrimaryKey = $otherModelObj->primaryKey;
|
||||||
|
?>
|
||||||
|
<div class="related">
|
||||||
|
<h3>Related <?php echo $otherPluralHumanName;?></h3>
|
||||||
|
<?php echo "<?php if(!empty(\${$singularVar}['{$assocName}'])):?>\n";?>
|
||||||
|
<table cellpadding = "0" cellspacing = "0">
|
||||||
|
<tr>
|
||||||
|
<?php
|
||||||
|
foreach($otherFields as $field) {
|
||||||
|
echo "\t\t<th>".Inflector::humanize($field['name'])."</th>\n";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
echo "\t<?php
|
||||||
|
\$i = 0;
|
||||||
|
foreach(\${$singularVar}['{$assocName}'] as \${$otherSingularVar}):
|
||||||
|
if(\$i++ % 2 == 0) {
|
||||||
|
\$class = ' class=\"altrow\"';
|
||||||
|
} else {
|
||||||
|
\$class = null;
|
||||||
|
}
|
||||||
|
?>\n";
|
||||||
|
echo "\t\t<tr<?php echo \$class;?>>\n";
|
||||||
|
|
||||||
|
foreach($otherFields as $field) {
|
||||||
|
echo "\t\t\t<td><?php echo \${$otherSingularVar}['{$field['name']}'];?></td>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "\t\t\t<td class=\"actions\">\n";
|
||||||
|
echo "\t\t\t\t<?php echo \$html->link('View', array('controller'=> '{$otherControllerPath}', 'action'=>'view', \${$otherSingularVar}['{$otherPrimaryKey}'])); ?>\n";
|
||||||
|
echo "\t\t\t\t<?php echo \$html->link('Edit', array('controller'=> '{$otherControllerPath}', 'action'=>'edit', \${$otherSingularVar}['{$otherPrimaryKey}'])); ?>\n";
|
||||||
|
echo "\t\t\t\t<?php echo \$html->link('Delete', array('controller'=> '{$otherControllerPath}', 'action'=>'delete', \${$otherSingularVar}['{$otherPrimaryKey}']), null, 'Are you sure you want to delete #' . \${$otherSingularVar}['{$otherPrimaryKey}'] . '?'); ?>\n";
|
||||||
|
echo "\t\t\t</td>\n";
|
||||||
|
echo "\t\t</tr>\n";
|
||||||
|
|
||||||
|
echo "\t<?php endforeach; ?>\n";
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
<?php echo "<?php endif; ?>\n\n";?>
|
||||||
|
<div class="actions">
|
||||||
|
<ul>
|
||||||
|
<li><?php echo "<?php echo \$html->link('New {$otherSingularHumanName}', array('controller'=> '{$otherControllerPath}', 'action'=>'add'));?> </li>\n";?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php endforeach;?>
|
Loading…
Add table
Reference in a new issue