Browse Source

Fix mistakes when generating $_accessible

The property needs to be a hash, not a list.
mark_story 12 years ago
parent
commit
b7cc3ffb45

+ 3 - 5
src/Console/Templates/default/classes/entity.ctp

@@ -24,17 +24,15 @@ use Cake\ORM\Entity;
 class <?= $name ?> extends Entity {
 
 <?php if (!empty($fields)): ?>
-<?php
-$fields = array_map(function($el) { return "'$el'"; }, $fields);
-?>
 /**
  * Fields that can be mass assigned using newEntity() or patchEntity().
  *
  * @var array
  */
 	protected $_accessible = [
-		<?= implode(",\n\t\t", $fields) ?>
-
+<?php foreach ($fields as $field): ?>
+		'<?= $field ?>' => false,
+<?php endforeach; ?>
 	];
 
 <?php endif ?>

+ 3 - 3
tests/TestCase/Console/Command/Task/ModelTaskTest.php

@@ -641,9 +641,9 @@ class ModelTaskTest extends TestCase {
 		$result = $this->Task->bakeEntity($model, $config);
 
 		$this->assertContains("protected \$_accessible = [", $result);
-		$this->assertContains("'title',", $result);
-		$this->assertContains("'body',", $result);
-		$this->assertContains("'published'", $result);
+		$this->assertContains("'title' => false,", $result);
+		$this->assertContains("'body' => false,", $result);
+		$this->assertContains("'published' => false", $result);
 		$this->assertNotContains("protected \$_hidden", $result);
 	}