Skip to content
This repository
Browse code

Replace Model::read() with Model::find('first') in baked controller

Removed references to Ajax and Javascript helpers
  • Loading branch information...
commit 035f727686883d6201207fff43e22c5d7c99cb85 1 parent 59e948f
ADmad authored September 30, 2012
2  lib/Cake/Console/Command/Task/ControllerTask.php
@@ -349,7 +349,7 @@ public function bakeTest($className) {
349 349
 	public function doHelpers() {
350 350
 		return $this->_doPropertyChoices(
351 351
 			__d('cake_console', "Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?"),
352  
-			__d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'")
  352
+			__d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Text, Js, Time'")
353 353
 		);
354 354
 	}
355 355
 
12  lib/Cake/Console/Templates/default/actions/controller_actions.ctp
@@ -36,11 +36,11 @@
36 36
  * @return void
37 37
  */
38 38
 	public function <?php echo $admin ?>view($id = null) {
39  
-		$this-><?php echo $currentModelName; ?>->id = $id;
40  
-		if (!$this-><?php echo $currentModelName; ?>->exists()) {
  39
+		if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
41 40
 			throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
42 41
 		}
43  
-		$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
  42
+		$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
  43
+		$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->find('first', $options));
44 44
 	}
45 45
 
46 46
 <?php $compact = array(); ?>
@@ -91,8 +91,7 @@
91 91
  * @return void
92 92
  */
93 93
 	public function <?php echo $admin; ?>edit($id = null) {
94  
-		$this-><?php echo $currentModelName; ?>->id = $id;
95  
-		if (!$this-><?php echo $currentModelName; ?>->exists()) {
  94
+		if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
96 95
 			throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
97 96
 		}
98 97
 		if ($this->request->is('post') || $this->request->is('put')) {
@@ -109,7 +108,8 @@
109 108
 <?php endif; ?>
110 109
 			}
111 110
 		} else {
112  
-			$this->request->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
  111
+			$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
  112
+			$this->request->data = $this-><?php echo $currentModelName; ?>->find('first', $options);
113 113
 		}
114 114
 <?php
115 115
 		foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
21  lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php
@@ -191,9 +191,9 @@ public function testDoHelpersNo() {
191 191
  */
192 192
 	public function testDoHelpersTrailingSpace() {
193 193
 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
194  
-		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne  '));
  194
+		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne  '));
195 195
 		$result = $this->Task->doHelpers();
196  
-		$expected = array('Javascript', 'Ajax', 'CustomOne');
  196
+		$expected = array('Text', 'Number', 'CustomOne');
197 197
 		$this->assertEquals($expected, $result);
198 198
 	}
199 199
 
@@ -204,9 +204,9 @@ public function testDoHelpersTrailingSpace() {
204 204
  */
205 205
 	public function testDoHelpersTrailingCommas() {
206 206
 		$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
207  
-		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne, , '));
  207
+		$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , '));
208 208
 		$result = $this->Task->doHelpers();
209  
-		$expected = array('Javascript', 'Ajax', 'CustomOne');
  209
+		$expected = array('Text', 'Number', 'CustomOne');
210 210
 		$this->assertEquals($expected, $result);
211 211
 	}
212 212
 
@@ -257,11 +257,11 @@ public function testDoComponentsTrailingCommas() {
257 257
 	public function testConfirmController() {
258 258
 		$controller = 'Posts';
259 259
 		$scaffold = false;
260  
-		$helpers = array('Ajax', 'Time');
  260
+		$helpers = array('Js', 'Time');
261 261
 		$components = array('Acl', 'Auth');
262 262
 
263 263
 		$this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");
264  
-		$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tAjax, Time");
  264
+		$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time");
265 265
 		$this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");
266 266
 		$this->Task->confirmController($controller, $scaffold, $helpers, $components);
267 267
 	}
@@ -272,7 +272,7 @@ public function testConfirmController() {
272 272
  * @return void
273 273
  */
274 274
 	public function testBake() {
275  
-		$helpers = array('Ajax', 'Time');
  275
+		$helpers = array('Js', 'Time');
276 276
 		$components = array('Acl', 'Auth');
277 277
 		$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
278 278
 
@@ -282,7 +282,7 @@ public function testBake() {
282 282
 		$this->assertContains(' * @property AuthComponent $Auth', $result);
283 283
 		$this->assertContains('class ArticlesController extends AppController', $result);
284 284
 		$this->assertContains("public \$components = array('Acl', 'Auth')", $result);
285  
-		$this->assertContains("public \$helpers = array('Ajax', 'Time')", $result);
  285
+		$this->assertContains("public \$helpers = array('Js', 'Time')", $result);
286 286
 		$this->assertContains("--actions--", $result);
287 287
 
288 288
 		$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
@@ -350,7 +350,8 @@ public function testBakeActionsUsingSessions() {
350 350
 
351 351
 		$this->assertContains('function view($id = null)', $result);
352 352
 		$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
353  
-		$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
  353
+		$this->assertContains("\$options = array('conditions' => array('BakeArticle.' . \$this->BakeArticle->primaryKey => \$id));", $result);
  354
+		$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);
354 355
 
355 356
 		$this->assertContains('function add()', $result);
356 357
 		$this->assertContains("if (\$this->request->is('post'))", $result);
@@ -389,7 +390,7 @@ public function testBakeActionsWithNoSessions() {
389 390
 
390 391
 		$this->assertContains('function view($id = null)', $result);
391 392
 		$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
392  
-		$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
  393
+		$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);
393 394
 
394 395
 		$this->assertContains('function add()', $result);
395 396
 		$this->assertContains("if (\$this->request->is('post'))", $result);

0 notes on commit 035f727

Please sign in to comment.
Something went wrong with that request. Please try again.