Browse Source

Update generated controller method code.

Use the 3.0 style conventions for the generated controller code. The
updated tests are not fully passing because of issues in the ORM code.
mark_story 12 years ago
parent
commit
7d7d91578d

+ 14 - 172
src/Console/Command/Task/ControllerTask.php

@@ -16,6 +16,7 @@ namespace Cake\Console\Command\Task;
 
 use Cake\Console\Shell;
 use Cake\Core\App;
+use Cake\ORM\TableRegistry;
 use Cake\Utility\ClassRegistry;
 use Cake\Utility\Inflector;
 
@@ -84,12 +85,6 @@ class ControllerTask extends BakeTask {
  */
 	public function all() {
 		$this->listAll();
-		ClassRegistry::config('Model', ['ds' => $this->connection]);
-
-		$admin = false;
-		if (!empty($this->params['admin'])) {
-			$admin = $this->Project->getPrefix();
-		}
 
 		$controllersCreated = 0;
 		foreach ($this->__tables as $table) {
@@ -97,12 +92,7 @@ class ControllerTask extends BakeTask {
 			$controller = $this->_controllerName($model);
 			$classname = App::classname($model, 'Model');
 			if ($classname) {
-				$actions = $this->bakeActions($controller);
-				if ($admin) {
-					$this->out(__d('cake_console', 'Adding %s methods', $admin));
-					$actions .= "\n" . $this->bakeActions($controller, $admin);
-				}
-				$this->bake($controller, $actions);
+				$this->bake($controller);
 				$this->bakeTest($controller);
 				$controllersCreated++;
 			}
@@ -114,183 +104,29 @@ class ControllerTask extends BakeTask {
 	}
 
 /**
- * Interactive
- *
- * @return void
- */
-	protected function _interactive() {
-		$this->interactive = true;
-		$this->hr();
-		$this->out(__d('cake_console', "Bake Controller\nPath: %s", $this->getPath()));
-		$this->hr();
-
-		if (empty($this->connection)) {
-			$this->connection = $this->DbConfig->getConfig();
-		}
-
-		$controllerName = $this->getName();
-		$this->hr();
-		$this->out(__d('cake_console', 'Baking %sController', $controllerName));
-		$this->hr();
-
-		$helpers = $components = [];
-		$actions = '';
-		$wannaBakeAdminCrud = 'n';
-		$useDynamicScaffold = 'n';
-		$wannaBakeCrud = 'y';
-
-		$question[] = __d('cake_console', "Would you like to build your controller interactively?");
-		if (file_exists($this->path . $controllerName . 'Controller.php')) {
-			$question[] = __d('cake_console', "Warning: Choosing no will overwrite the %sController.", $controllerName);
-		}
-		$doItInteractive = $this->in(implode("\n", $question), ['y', 'n'], 'y');
-
-		if (strtolower($doItInteractive) === 'y') {
-			$this->interactive = true;
-			$useDynamicScaffold = $this->in(
-				__d('cake_console', "Would you like to use dynamic scaffolding?"), ['y', 'n'], 'n'
-			);
-
-			if (strtolower($useDynamicScaffold) === 'y') {
-				$wannaBakeCrud = 'n';
-				$actions = 'scaffold';
-			} else {
-				list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
-
-				$helpers = $this->doHelpers();
-				$components = $this->doComponents();
-
-				$wannaUseSession = $this->in(
-					__d('cake_console', "Would you like to use Session flash messages?"), array('y', 'n'), 'y'
-				);
-
-				if (strtolower($wannaUseSession) === 'y') {
-					array_push($components, 'Session');
-				}
-			}
-		} else {
-			list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
-		}
-
-		if (strtolower($wannaBakeCrud) === 'y') {
-			$actions = $this->bakeActions($controllerName, null);
-		}
-		if (strtolower($wannaBakeAdminCrud) === 'y') {
-			$admin = $this->Project->getPrefix();
-			$actions .= $this->bakeActions($controllerName, $admin);
-		}
-
-		$baked = false;
-		if ($this->interactive === true) {
-			$this->confirmController($controllerName, $useDynamicScaffold, $helpers, $components);
-			$looksGood = $this->in(__d('cake_console', 'Look okay?'), ['y', 'n'], 'y');
-
-			if (strtolower($looksGood) === 'y') {
-				$baked = $this->bake($controllerName, $actions, $helpers, $components);
-				if ($baked && $this->_checkUnitTest()) {
-					$this->bakeTest($controllerName);
-				}
-			}
-		} else {
-			$baked = $this->bake($controllerName, $actions, $helpers, $components);
-			if ($baked && $this->_checkUnitTest()) {
-				$this->bakeTest($controllerName);
-			}
-		}
-		return $baked;
-	}
-
-/**
- * Confirm a to be baked controller with the user
- *
- * @param string $controllerName
- * @param string $useDynamicScaffold
- * @param array $helpers
- * @param array $components
- * @return void
- */
-	public function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) {
-		$this->out();
-		$this->hr();
-		$this->out(__d('cake_console', 'The following controller will be created:'));
-		$this->hr();
-		$this->out(__d('cake_console', "Controller Name:\n\t%s", $controllerName));
-
-		if (strtolower($useDynamicScaffold) === 'y') {
-			$this->out("public \$scaffold;");
-		}
-
-		$properties = [
-			'helpers' => __d('cake_console', 'Helpers:'),
-			'components' => __d('cake_console', 'Components:'),
-		];
-
-		foreach ($properties as $var => $title) {
-			if (count($$var)) {
-				$output = '';
-				$length = count($$var);
-				foreach ($$var as $i => $propElement) {
-					if ($i != $length - 1) {
-						$output .= ucfirst($propElement) . ', ';
-					} else {
-						$output .= ucfirst($propElement);
-					}
-				}
-				$this->out($title . "\n\t" . $output);
-			}
-		}
-		$this->hr();
-	}
-
-/**
- * Interact with the user and ask about which methods (admin or regular they want to bake)
- *
- * @return array Array containing (bakeRegular, bakeAdmin) answers
- */
-	protected function _askAboutMethods() {
-		$wannaBakeCrud = $this->in(
-			__d('cake_console', "Would you like to create some basic class methods \n(index(), add(), view(), edit())?"),
-			['y', 'n'], 'n'
-		);
-		$wannaBakeAdminCrud = $this->in(
-			__d('cake_console', "Would you like to create the basic class methods for admin routing?"),
-			['y', 'n'], 'n'
-		);
-		return [$wannaBakeCrud, $wannaBakeAdminCrud];
-	}
-
-/**
  * Bake scaffold actions
  *
  * @param string $controllerName Controller name
- * @param string $admin Admin route to use
  * @return string Baked actions
  */
-	public function bakeActions($controllerName, $admin = null) {
-		$currentModelName = $modelImport = $this->_modelName($controllerName);
+	public function bakeActions($controllerName) {
+		$currentModelName = $controllerName;
 		$plugin = $this->plugin;
 		if ($plugin) {
 			$plugin .= '.';
 		}
-		$classname = App::classname($plugin . $modelImport, 'Model');
-		if (!class_exists($modelImport)) {
-			$this->err(__d('cake_console', 'You must have a model for this class to build basic methods. Please try again.'));
-			return $this->_stop();
-		}
 
-		$modelObj = ClassRegistry::init($currentModelName);
+		$modelObj = TableRegistry::get($currentModelName);
+
 		$controllerPath = $this->_controllerPath($controllerName);
 		$pluralName = $this->_pluralName($currentModelName);
-		$singularName = Inflector::variable($currentModelName);
+		$singularName = Inflector::variable(Inflector::singularize($currentModelName));
 		$singularHumanName = $this->_singularHumanName($controllerName);
 		$pluralHumanName = $this->_pluralName($controllerName);
-		$displayField = $modelObj->displayField;
-		$primaryKey = $modelObj->primaryKey;
 
 		$this->Template->set(compact(
 			'plugin', 'admin', 'controllerPath', 'pluralName', 'singularName',
-			'singularHumanName', 'pluralHumanName', 'modelObj', 'currentModelName',
-			'displayField', 'primaryKey'
+			'singularHumanName', 'pluralHumanName', 'modelObj', 'currentModelName'
 		));
 		$actions = $this->Template->generate('actions', 'controller_actions');
 		return $actions;
@@ -326,6 +162,12 @@ class ControllerTask extends BakeTask {
 		$this->bakeTest($controllerName);
 	}
 
+/**
+ * Generate the controller code
+ *
+ * @param string $controllerName The name of the controller.
+ * @param array $data The data to turn into code.
+ */
 	public function bakeController($controllerName, $data) {
 		$data += [
 			'name' => null,

+ 35 - 49
src/Console/Templates/default/actions/controller_actions.ctp

@@ -17,40 +17,37 @@
 ?>
 
 /**
- * <?= $admin ?>index method
+ * Index method
  *
  * @return void
  */
-	public function <?= $admin ?>index() {
-		$this-><?= $currentModelName ?>->recursive = 0;
-		$this->set('<?= $pluralName ?>', $this->paginate());
+	public function index() {
+		$this->set('<?= $pluralName ?>', $this->paginate($this-><?= $currentModelName ?>));
 	}
 
 /**
- * <?= $admin ?>view method
+ * View method
  *
  * @throws NotFoundException
  * @param string $id
  * @return void
  */
-	public function <?= $admin ?>view($id = null) {
-		if (!$this-><?= $currentModelName; ?>->exists($id)) {
-			throw new NotFoundException(__('Invalid <?= strtolower($singularHumanName); ?>'));
-		}
-		$options = ['conditions' => ['<?= $currentModelName; ?>.' . $this-><?= $currentModelName; ?>->primaryKey => $id]];
-		$this->set('<?= $singularName; ?>', $this-><?= $currentModelName; ?>->find('first', $options));
+	public function view($id = null) {
+		$<?= $singularName?> = $this-><?= $currentModelName ?>->get($id);
+		$this->set('<?= $singularName; ?>', $<?= $singularName; ?>);
 	}
 
 <?php $compact = []; ?>
 /**
- * <?= $admin ?>add method
+ * Add method
  *
  * @return void
  */
-	public function <?= $admin ?>add() {
+	public function add() {
+		$<?= $singularName ?> = $this-><?= $currentModelName ?>->newEntity();
 		if ($this->request->is('post')) {
-			$this-><?= $currentModelName; ?>->create();
-			if ($this-><?= $currentModelName; ?>->save($this->request->data)) {
+			$<?= $singularName ?> = $this-><?= $currentModelName ?>->patchEntity($<?= $singularName ?>, $this->request->data);
+			if ($this-><?= $currentModelName; ?>->save($<?= $singularName ?>)) {
 				$this->Session->setFlash(__('The <?= strtolower($singularHumanName); ?> has been saved.'));
 				return $this->redirect(['action' => 'index']);
 			} else {
@@ -58,54 +55,46 @@
 			}
 		}
 <?php
-	foreach (['belongsTo', 'hasAndBelongsToMany'] as $assoc):
-		foreach ($modelObj->{$assoc} as $associationName => $relation):
-			if (!empty($associationName)):
-				$otherModelName = $this->_modelName($associationName);
-				$otherPluralName = $this->_pluralName($associationName);
-				echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
-				$compact[] = "'{$otherPluralName}'";
-			endif;
+	foreach (['BelongsTo', 'BelongsToMany'] as $assoc):
+		foreach ($modelObj->associations()->type($assoc) as $association):
+			$otherName = $association->target()->alias();
+			$otherPlural = $this->_pluralName($otherName);
+			echo "\t\t\${$otherPlural} = \$this->{$currentModelName}->association('{$otherName}')->find('list');\n";
+			$compact[] = "'{$otherPlural}'";
 		endforeach;
 	endforeach;
 	if (!empty($compact)):
-		echo "\t\t\$this->set(compact(".join(', ', $compact)."));\n";
+		echo "\t\t\$this->set(compact(" . join(', ', $compact) . "));\n";
 	endif;
 ?>
 	}
 
 <?php $compact = []; ?>
 /**
- * <?= $admin ?>edit method
+ * Edit method
  *
  * @throws NotFoundException
  * @param string $id
  * @return void
  */
-	public function <?= $admin; ?>edit($id = null) {
-		if (!$this-><?= $currentModelName; ?>->exists($id)) {
-			throw new NotFoundException(__('Invalid <?= strtolower($singularHumanName); ?>'));
-		}
+	public function edit($id = null) {
+		$<?= $singularName ?> = $this-><?= $currentModelName ?>->get($id);
 		if ($this->request->is(['post', 'put'])) {
-			if ($this-><?= $currentModelName; ?>->save($this->request->data)) {
+			$<?= $singularName ?> = $this-><?= $currentModelName ?>->patchEntity($<?= $singularName ?>, $this->request->data);
+			if ($this-><?= $currentModelName; ?>->save($<?= $singularName ?>)) {
 				$this->Session->setFlash(__('The <?= strtolower($singularHumanName); ?> has been saved.'));
 				return $this->redirect(['action' => 'index']);
 			} else {
 				$this->Session->setFlash(__('The <?= strtolower($singularHumanName); ?> could not be saved. Please, try again.'));
 			}
-		} else {
-			$options = ['conditions' => ['<?= $currentModelName; ?>.' . $this-><?= $currentModelName; ?>->primaryKey => $id]];
-			$this->request->data = $this-><?= $currentModelName; ?>->find('first', $options);
 		}
 <?php
-		foreach (['belongsTo', 'hasAndBelongsToMany'] as $assoc):
-			foreach ($modelObj->{$assoc} as $associationName => $relation):
-				if (!empty($associationName)):
-					$otherModelName = $this->_modelName($associationName);
-					$otherPluralName = $this->_pluralName($associationName);
-					echo "\t\t\${$otherPluralName} = \$this->{$currentModelName}->{$otherModelName}->find('list');\n";
-					$compact[] = "'{$otherPluralName}'";
-				endif;
+		foreach (['BelongsTo', 'BelongsToMany'] as $assoc):
+			foreach ($modelObj->associations()->type($assoc) as $association):
+				$otherName = $association->target()->alias();
+				$otherPlural = $this->_pluralName($otherName);
+				echo "\t\t\${$otherPlural} = \$this->{$currentModelName}->association('{$otherName}')->find('list');\n";
+				$compact[] = "'{$otherPlural}'";
 			endforeach;
 		endforeach;
 		if (!empty($compact)):
@@ -115,19 +104,16 @@
 	}
 
 /**
- * <?= $admin ?>delete method
+ * Delete method
  *
  * @throws NotFoundException
  * @param string $id
  * @return void
  */
-	public function <?= $admin; ?>delete($id = null) {
-		$this-><?= $currentModelName; ?>->id = $id;
-		if (!$this-><?= $currentModelName; ?>->exists()) {
-			throw new NotFoundException(__('Invalid <?= strtolower($singularHumanName); ?>'));
-		}
-		$this->request->onlyAllow('post', 'delete');
-		if ($this-><?= $currentModelName; ?>->delete()) {
+	public function delete($id = null) {
+		$<?= $singularName ?> = $this-><?= $currentModelName ?>->get($id);
+		$this->request->allowMethod('post', 'delete');
+		if ($this-><?= $currentModelName; ?>->delete($<?= $singularName ?>)) {
 			$this->Session->setFlash(__('The <?= strtolower($singularHumanName); ?> has been deleted.'));
 		} else {
 			$this->Session->setFlash(__('The <?= strtolower($singularHumanName); ?> could not be deleted. Please, try again.'));

+ 8 - 177
tests/TestCase/Console/Command/Task/ControllerTaskTest.php

@@ -20,8 +20,8 @@ use Cake\Console\Shell;
 use Cake\Core\App;
 use Cake\Core\Plugin;
 use Cake\ORM\Table;
+use Cake\ORM\TableRegistry;
 use Cake\TestSuite\TestCase;
-use Cake\Utility\ClassRegistry;
 use Cake\View\Helper;
 
 /**
@@ -36,11 +36,6 @@ class BakeArticlesTable extends Table {
 
 }
 
-class_alias(
-	'Cake\Test\TestCase\Console\Command\Task\BakeArticlesTable',
-	'TestApp\Model\Table\BakeArticlesTable'
-);
-
 /**
  * ControllerTaskTest class
  *
@@ -148,94 +143,6 @@ class ControllerTaskTest extends TestCase {
 	}
 
 /**
- * test getting helper values
- *
- * @return void
- */
-	public function testDoHelpersTrailingSpace() {
-		$this->markTestIncomplete();
-		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
-		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne  '));
-		$result = $this->Task->doHelpers();
-		$expected = array('Text', 'Number', 'CustomOne');
-		$this->assertEquals($expected, $result);
-	}
-
-/**
- * test doHelpers with extra commas
- *
- * @return void
- */
-	public function testDoHelpersTrailingCommas() {
-		$this->markTestIncomplete();
-		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
-		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , '));
-		$result = $this->Task->doHelpers();
-		$expected = array('Text', 'Number', 'CustomOne');
-		$this->assertEquals($expected, $result);
-	}
-
-/**
- * test component interactions
- *
- * @return void
- */
-	public function testDoComponentsNo() {
-		$this->markTestIncomplete();
-		$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
-		$result = $this->Task->doComponents();
-		$this->assertSame(array('Paginator'), $result);
-	}
-
-/**
- * test components with spaces
- *
- * @return void
- */
-	public function testDoComponentsTrailingSpaces() {
-		$this->markTestIncomplete();
-		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
-		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security  '));
-
-		$result = $this->Task->doComponents();
-		$expected = array('Paginator', 'RequestHandler', 'Security');
-		$this->assertEquals($expected, $result);
-	}
-
-/**
- * test components with commas
- *
- * @return void
- */
-	public function testDoComponentsTrailingCommas() {
-		$this->markTestIncomplete();
-		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
-		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' RequestHandler, Security, , '));
-
-		$result = $this->Task->doComponents();
-		$expected = array('Paginator', 'RequestHandler', 'Security');
-		$this->assertEquals($expected, $result);
-	}
-
-/**
- * test Confirming controller user interaction
- *
- * @return void
- */
-	public function testConfirmController() {
-		$this->markTestIncomplete();
-		$controller = 'Posts';
-		$scaffold = false;
-		$helpers = array('Js', 'Time');
-		$components = array('Acl', 'Auth');
-
-		$this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");
-		$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time");
-		$this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");
-		$this->Task->confirmController($controller, $scaffold, $helpers, $components);
-	}
-
-/**
  * test the bake method
  *
  * @return void
@@ -299,10 +206,13 @@ class ControllerTaskTest extends TestCase {
  *
  * @return void
  */
-	public function testBakeActionsUsingSessions() {
-		$this->markTestIncomplete();
-		$result = $this->Task->bakeActions('BakeArticles', null, true);
-		$expected = file_get_contents(CAKE . 'Test' . DS . 'bake_compare' . DS . 'Controller' . DS . 'ActionsUsingSessions.ctp');
+	public function testBakeActions() {
+		TableRegistry::get('BakeArticles', [
+			'className' => __NAMESPACE__ . '\BakeArticlesTable'
+		]);
+
+		$result = $this->Task->bakeActions('BakeArticles');
+		$expected = file_get_contents(CORE_TESTS . 'bake_compare/Controller/Actions.ctp');
 		$this->assertTextEquals($expected, $result);
 
 		$result = $this->Task->bakeActions('BakeArticles', 'admin_', true);
@@ -347,85 +257,6 @@ class ControllerTaskTest extends TestCase {
 	}
 
 /**
- * test Interactive mode.
- *
- * @return void
- */
-	public function testInteractive() {
-		$this->markTestIncomplete();
-		$count = count($this->Task->listAll('test'));
-		if ($count != count($this->fixtures)) {
-			$this->markTestSkipped('Additional tables detected.');
-		}
-
-		$this->Task->connection = 'test';
-		$this->Task->path = '/my/path/';
-
-		$this->Task->expects($this->any())->method('in')
-			->will($this->onConsecutiveCalls(
-				'1',
-				'y', // build interactive
-				'n', // build no scaffolds
-				'y', // build normal methods
-				'n', // build admin methods
-				'n', // helpers?
-				'n', // components?
-				'y', // sessions ?
-				'y' // looks good?
-			));
-
-		$filename = '/my/path/BakeArticlesController.php';
-		$this->Task->expects($this->once())->method('createFile')->with(
-			$filename,
-			$this->stringContains('class BakeArticlesController')
-		);
-		$this->Task->execute();
-	}
-
-/**
- * test Interactive mode.
- *
- * @return void
- */
-	public function testInteractiveAdminMethodsNotInteractive() {
-		$this->markTestIncomplete();
-		$count = count($this->Task->listAll('test'));
-		if ($count != count($this->fixtures)) {
-			$this->markTestSkipped('Additional tables detected.');
-		}
-
-		$this->Task->connection = 'test';
-		$this->Task->interactive = true;
-		$this->Task->path = '/my/path/';
-
-		$this->Task->expects($this->any())->method('in')
-			->will($this->onConsecutiveCalls(
-				'1',
-				'y', // build interactive
-				'n', // build no scaffolds
-				'y', // build normal methods
-				'y', // build admin methods
-				'n', // helpers?
-				'n', // components?
-				'y', // sessions ?
-				'y' // looks good?
-			));
-
-		$this->Task->Project->expects($this->any())
-			->method('getPrefix')
-			->will($this->returnValue('admin_'));
-
-		$filename = '/my/path/BakeArticlesController.php';
-		$this->Task->expects($this->once())->method('createFile')->with(
-			$filename,
-			$this->stringContains('class BakeArticlesController')
-		)->will($this->returnValue(true));
-
-		$result = $this->Task->execute();
-		$this->assertRegExp('/admin_index/', $result);
-	}
-
-/**
  * test that execute runs all when the first arg == all
  *
  * @return void

+ 81 - 0
tests/bake_compare/Controller/Actions.ctp

@@ -0,0 +1,81 @@
+
+/**
+ * Index method
+ *
+ * @return void
+ */
+	public function index() {
+		$this->set('bakeArticles', $this->paginate($this->BakeArticles));
+	}
+
+/**
+ * View method
+ *
+ * @throws NotFoundException
+ * @param string $id
+ * @return void
+ */
+	public function view($id = null) {
+		$bakeArticle = $this->BakeArticles->get($id);
+		$this->set('bakeArticle', $bakeArticle);
+	}
+
+/**
+ * Add method
+ *
+ * @return void
+ */
+	public function add() {
+		$bakeArticle = $this->BakeArticles->newEntity();
+		if ($this->request->is('post')) {
+			$bakeArticle = $this->BakeArticles->patchEntity($bakeArticle, $this->request->data);
+			if ($this->BakeArticles->save($bakeArticle)) {
+				$this->Session->setFlash(__('The bake article has been saved.'));
+				return $this->redirect(['action' => 'index']);
+			} else {
+				$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));
+			}
+		}
+		$bakeTags = $this->BakeArticles->association('BakeTags')->find('list');
+		$this->set(compact('bakeTags'));
+	}
+
+/**
+ * Edit method
+ *
+ * @throws NotFoundException
+ * @param string $id
+ * @return void
+ */
+	public function edit($id = null) {
+		$bakeArticle = $this->BakeArticles->get($id);
+		if ($this->request->is(['post', 'put'])) {
+			$bakeArticle = $this->BakeArticles->patchEntity($bakeArticle, $this->request->data);
+			if ($this->BakeArticles->save($bakeArticle)) {
+				$this->Session->setFlash(__('The bake article has been saved.'));
+				return $this->redirect(['action' => 'index']);
+			} else {
+				$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));
+			}
+		}
+		$bakeTags = $this->BakeArticles->association('BakeTags')->find('list');
+		$this->set(compact('bakeTags'));
+	}
+
+/**
+ * Delete method
+ *
+ * @throws NotFoundException
+ * @param string $id
+ * @return void
+ */
+	public function delete($id = null) {
+		$bakeArticle = $this->BakeArticles->get($id);
+		$this->request->allowMethod('post', 'delete');
+		if ($this->BakeArticles->delete($bakeArticle)) {
+			$this->Session->setFlash(__('The bake article has been deleted.'));
+		} else {
+			$this->Session->setFlash(__('The bake article could not be deleted. Please, try again.'));
+		}
+		return $this->redirect(['action' => 'index']);
+	}

+ 0 - 91
tests/bake_compare/Controller/ActionsUsingSessions.ctp

@@ -1,91 +0,0 @@
-
-/**
- * index method
- *
- * @return void
- */
-	public function index() {
-		$this->BakeArticle->recursive = 0;
-		$this->set('bakeArticles', $this->Paginator->paginate());
-	}
-
-/**
- * view method
- *
- * @throws NotFoundException
- * @param string $id
- * @return void
- */
-	public function view($id = null) {
-		if (!$this->BakeArticle->exists($id)) {
-			throw new NotFoundException(__('Invalid bake article'));
-		}
-		$options = array('conditions' => array('BakeArticle.' . $this->BakeArticle->primaryKey => $id));
-		$this->set('bakeArticle', $this->BakeArticle->find('first', $options));
-	}
-
-/**
- * add method
- *
- * @return void
- */
-	public function add() {
-		if ($this->request->is('post')) {
-			$this->BakeArticle->create();
-			if ($this->BakeArticle->save($this->request->data)) {
-				$this->Session->setFlash(__('The bake article has been saved.'));
-				return $this->redirect(array('action' => 'index'));
-			} else {
-				$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));
-			}
-		}
-		$bakeTags = $this->BakeArticle->BakeTag->find('list');
-		$this->set(compact('bakeTags'));
-	}
-
-/**
- * edit method
- *
- * @throws NotFoundException
- * @param string $id
- * @return void
- */
-	public function edit($id = null) {
-		if (!$this->BakeArticle->exists($id)) {
-			throw new NotFoundException(__('Invalid bake article'));
-		}
-		if ($this->request->is(array('post', 'put'))) {
-			if ($this->BakeArticle->save($this->request->data)) {
-				$this->Session->setFlash(__('The bake article has been saved.'));
-				return $this->redirect(array('action' => 'index'));
-			} else {
-				$this->Session->setFlash(__('The bake article could not be saved. Please, try again.'));
-			}
-		} else {
-			$options = array('conditions' => array('BakeArticle.' . $this->BakeArticle->primaryKey => $id));
-			$this->request->data = $this->BakeArticle->find('first', $options);
-		}
-		$bakeTags = $this->BakeArticle->BakeTag->find('list');
-		$this->set(compact('bakeTags'));
-	}
-
-/**
- * delete method
- *
- * @throws NotFoundException
- * @param string $id
- * @return void
- */
-	public function delete($id = null) {
-		$this->BakeArticle->id = $id;
-		if (!$this->BakeArticle->exists()) {
-			throw new NotFoundException(__('Invalid bake article'));
-		}
-		$this->request->allowMethod('post', 'delete');
-		if ($this->BakeArticle->delete()) {
-			$this->Session->setFlash(__('The bake article has been deleted.'));
-		} else {
-			$this->Session->setFlash(__('The bake article could not be deleted. Please, try again.'));
-		}
-		return $this->redirect(array('action' => 'index'));
-	}