Browse Source

Fix a few mistakes.

* postLink() doesn't accept null anymore
* variable names were incorrect.
* missing HTML escaping
mark_story 12 years ago
parent
commit
ba82865f4e

+ 3 - 0
src/Console/Command/Task/ViewTask.php

@@ -107,6 +107,7 @@ class ViewTask extends BakeTask {
 
 		if (empty($this->args)) {
 			$this->out(__d('cake_console', 'Possible tables to bake views for based on your current database:'));
+			$this->Model->connection = $this->connection;
 			foreach ($this->Model->listAll() as $table) {
 				$this->out('- ' . $this->_controllerName($table));
 			}
@@ -432,6 +433,7 @@ class ViewTask extends BakeTask {
 			'short' => 'c',
 			'help' => __d('cake_console', 'The connection the connected model is on.')
 		])->addOption('force', [
+			'boolean' => true,
 			'short' => 'f',
 			'help' => __d('cake_console', 'Force overwriting existing files without prompting.')
 		])->addOption('prefix', [
@@ -463,6 +465,7 @@ class ViewTask extends BakeTask {
 
 				$associations[$type][$assocName] = [
 					'property' => $assoc->property(),
+					'variable' => Inflector::variable($assocName),
 					'primaryKey' => (array)$target->primaryKey(),
 					'displayField' => $target->displayField(),
 					'foreignKey' => $assoc->foreignKey(),

+ 1 - 1
src/Console/Templates/default/views/form.ctp

@@ -29,7 +29,7 @@ use Cake\Utility\Inflector;
 		}
 		if (!empty($associations['BelongsToMany'])) {
 			foreach ($associations['BelongsToMany'] as $assocName => $assocData) {
-				echo "\t\techo \$this->Form->input('{$assocName}._ids', ['options' => ${$assocName}]);\n";
+				echo "\t\techo \$this->Form->input('{$assocName}._ids', ['options' => \${$assocData['variable']}]);\n";
 			}
 		}
 		echo "\t?>\n";

+ 4 - 5
src/Console/Templates/default/views/index.ctp

@@ -47,9 +47,9 @@ use Cake\Utility\Inflector;
 		$pk = "\${$singularVar}->{$primaryKey[0]}";
 
 		echo "\t\t<td class=\"actions\">\n";
-		echo "\t\t\t<?= \$this->Html->link(__('View'), ['action' => 'view', {$pk}]]); ?>\n";
-		echo "\t\t\t<?= \$this->Html->link(__('Edit'), ['action' => 'edit', {$pk}]]); ?>\n";
-		echo "\t\t\t<?= \$this->Form->postLink(__('Delete'), ['action' => 'delete', {$pk}], null, __('Are you sure you want to delete # %s?', {$pk})); ?>\n";
+		echo "\t\t\t<?= \$this->Html->link(__('View'), ['action' => 'view', {$pk}]); ?>\n";
+		echo "\t\t\t<?= \$this->Html->link(__('Edit'), ['action' => 'edit', {$pk}]); ?>\n";
+		echo "\t\t\t<?= \$this->Form->postLink(__('Delete'), ['action' => 'delete', {$pk}], [], __('Are you sure you want to delete # %s?', {$pk})); ?>\n";
 		echo "\t\t</td>\n";
 	echo "\t</tr>\n";
 
@@ -59,8 +59,7 @@ use Cake\Utility\Inflector;
 	<p>
 	<?= "<?php
 	echo \$this->Paginator->counter();
-	?>"; ?>
-	</p>
+	?>"; ?></p>
 	<div class="paging">
 	<?php
 		echo "<?php\n";

+ 7 - 7
src/Console/Templates/default/views/view.ctp

@@ -24,8 +24,8 @@ foreach ($fields as $field) {
 		foreach ($associations['BelongsTo'] as $alias => $details) {
 			if ($field === $details['foreignKey']) {
 				$isKey = true;
-				echo "\t\t<dt><?= __('" . Inflector::humanize(Inflector::underscore($alias)) . "'); ?></dt>\n";
-				echo "\t\t<dd>\n\t\t\t<?= \$this->Html->link(\${$singularVar}->{$details['property']}->{$details['displayField']}, ['controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}->{$details['primaryKey'][0]}]); ?>\n\t\t\t&nbsp;\n\t\t</dd>\n";
+				echo "\t\t<dt><?= __('" . Inflector::humanize(Inflector::underscore($details['property'])) . "'); ?></dt>\n";
+				echo "\t\t<dd>\n\t\t\t<?= \$this->Html->link(\${$singularVar}->{$details['property']}->{$details['displayField']}, ['controller' => '{$details['controller']}', 'action' => 'view', \${$singularVar}->{$details['property']}->{$details['primaryKey'][0]}]); ?>\n\t\t\t&nbsp;\n\t\t</dd>\n";
 				break;
 			}
 		}
@@ -45,7 +45,7 @@ foreach ($fields as $field) {
 	$pk = "\${$singularVar}->{$primaryKey[0]}";
 
 	echo "\t\t<li><?= \$this->Html->link(__('Edit " . $singularHumanName ."'), ['action' => 'edit', {$pk}]); ?> </li>\n";
-	echo "\t\t<li><?= \$this->Form->postLink(__('Delete " . $singularHumanName . "'), ['action' => 'delete', {$pk}], null, __('Are you sure you want to delete # %s?', {$pk})); ?> </li>\n";
+	echo "\t\t<li><?= \$this->Form->postLink(__('Delete " . $singularHumanName . "'), ['action' => 'delete', {$pk}], [], __('Are you sure you want to delete # %s?', {$pk})); ?> </li>\n";
 	echo "\t\t<li><?= \$this->Html->link(__('List " . $pluralHumanName . "'), ['action' => 'index']); ?> </li>\n";
 	echo "\t\t<li><?= \$this->Html->link(__('New " . $singularHumanName . "'), ['action' => 'add']); ?> </li>\n";
 
@@ -72,7 +72,7 @@ if (!empty($associations['HasOne'])) :
 	<?php
 			foreach ($details['fields'] as $field) {
 				echo "\t\t<dt><?= __('" . Inflector::humanize($field) . "'); ?></dt>\n";
-				echo "\t\t<dd>\n\t<?= \${$singularVar}->{$details['property']}->{$field}; ?>\n&nbsp;</dd>\n";
+				echo "\t\t<dd>\n\t<?= h(\${$singularVar}->{$details['property']}->{$field}) ?>\n&nbsp;</dd>\n";
 			}
 	?>
 		</dl>
@@ -102,7 +102,7 @@ foreach ($relations as $alias => $details):
 <div class="related">
 	<h3><?= "<?= __('Related " . $otherPluralHumanName . "'); ?>"; ?></h3>
 	<?= "<?php if (!empty(\${$singularVar}->{$alias})): ?>\n"; ?>
-	<table cellpadding = "0" cellspacing = "0">
+	<table cellpadding="0" cellspacing="0">
 	<tr>
 <?php
 			foreach ($details['fields'] as $field) {
@@ -115,7 +115,7 @@ foreach ($relations as $alias => $details):
 echo "\t<?php foreach (\${$singularVar}->{$details['property']} as \${$otherSingularVar}): ?>\n";
 		echo "\t\t<tr>\n";
 			foreach ($details['fields'] as $field) {
-				echo "\t\t\t<td><?= \${$otherSingularVar}->{$field} ?></td>\n";
+				echo "\t\t\t<td><?= h(\${$otherSingularVar}->{$field}) ?></td>\n";
 			}
 
 			$otherPk = "\${$otherSingularVar}->{$details['primaryKey'][0]}";
@@ -123,7 +123,7 @@ echo "\t<?php foreach (\${$singularVar}->{$details['property']} as \${$otherSing
 			echo "\t\t\t<td class=\"actions\">\n";
 			echo "\t\t\t\t<?= \$this->Html->link(__('View'), ['controller' => '{$details['controller']}', 'action' => 'view', {$otherPk}]); ?>\n";
 			echo "\t\t\t\t<?= \$this->Html->link(__('Edit'), ['controller' => '{$details['controller']}', 'action' => 'edit', {$otherPk}]); ?>\n";
-			echo "\t\t\t\t<?= \$this->Form->postLink(__('Delete'), ['controller' => '{$details['controller']}', 'action' => 'delete', {$otherPk}], null, __('Are you sure you want to delete # %s?', {$otherPk})); ?>\n";
+			echo "\t\t\t\t<?= \$this->Form->postLink(__('Delete'), ['controller' => '{$details['controller']}', 'action' => 'delete', {$otherPk}], [], __('Are you sure you want to delete # %s?', {$otherPk})); ?>\n";
 			echo "\t\t\t</td>\n";
 		echo "\t\t</tr>\n";