Skip to content

Commit

Permalink
Removed adding of Html and Form helper by default to baked controller…
Browse files Browse the repository at this point in the history
…s as its not DRY and they are alrady inherited from Controller class. If var helpers is declared in AppController, Html and Form should be included there.
  • Loading branch information
ADmad committed Dec 7, 2009
1 parent 779479f commit e2c4c0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 9 additions & 5 deletions cake/console/templates/default/classes/controller.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ class <?php echo $controllerName; ?>Controller extends <?php echo $plugin; ?>App
var $scaffold;
<?php else: ?>
<?php
echo "\tvar \$helpers = array('Html', 'Form'";
if (count($helpers)):
foreach ($helpers as $help):
echo ", '" . Inflector::camelize($help) . "'";
endforeach;
echo "\tvar \$helpers = array(";
for ($i = 0, $len = count($helpers); $i < $len; $i++):
if ($i != $len - 1):
echo "'" . Inflector::camelize($helpers[$i]) . "', ";
else:
echo "'" . Inflector::camelize($helpers[$i]) . "'";
endif;
endfor;
echo ");\n";
endif;
echo ");\n";

if (count($components)):
echo "\tvar \$components = array(";
Expand Down
8 changes: 7 additions & 1 deletion cake/tests/cases/console/libs/tasks/controller.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,20 @@ function testBake() {
$result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
$this->assertPattern('/class ArticlesController extends AppController/', $result);
$this->assertPattern('/\$components \= array\(\'Acl\', \'Auth\'\)/', $result);
$this->assertPattern('/\$helpers \= array\(\'Html\', \'Form\', \'Ajax\', \'Time\'\)/', $result);
$this->assertPattern('/\$helpers \= array\(\'Ajax\', \'Time\'\)/', $result);
$this->assertPattern('/\-\-actions\-\-/', $result);

$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
$this->assertPattern('/class ArticlesController extends AppController/', $result);
$this->assertPattern('/var \$scaffold/', $result);
$this->assertNoPattern('/helpers/', $result);
$this->assertNoPattern('/components/', $result);

$result = $this->Task->bake('Articles', '--actions--', array(), array());
$this->assertPattern('/class ArticlesController extends AppController/', $result);
$this->assertNoPattern('/components/', $result);
$this->assertNoPattern('/helpers/', $result);
$this->assertPattern('/\-\-actions\-\-/', $result);
}

/**
Expand Down

0 comments on commit e2c4c0d

Please sign in to comment.