Permalink
Browse files

Removing the �with� key from otherFields array, also fixing the page …

…title. Tests added.
  • Loading branch information...
1 parent e1b0c41 commit 39dd15d3f6dd9ee66b21da7a76ec1a12f72e2ebb @renan renan committed Jan 19, 2010
View
17 cake/libs/controller/scaffold.php
@@ -163,7 +163,7 @@ function __construct(&$controller, $params) {
$this->{$var} = $controller->{$var};
}
- $this->redirect = array('action'=> 'index');
+ $this->redirect = array('action' => 'index');
$this->modelClass = $controller->modelClass;
$this->modelKey = $controller->modelKey;
@@ -177,8 +177,7 @@ function __construct(&$controller, $params) {
$this->ScaffoldModel =& $this->controller->{$this->modelClass};
$this->scaffoldTitle = Inflector::humanize($this->viewPath);
$this->scaffoldActions = $controller->scaffold;
- $this->controller->pageTitle = __('Scaffold :: ', true)
- . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
+ $title_for_layout = __('Scaffold :: ', true) . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
$modelClass = $this->controller->modelClass;
$primaryKey = $this->ScaffoldModel->primaryKey;
$displayField = $this->ScaffoldModel->displayField;
@@ -190,7 +189,7 @@ function __construct(&$controller, $params) {
$associations = $this->__associations();
$this->controller->set(compact(
- 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
+ 'title_for_layout', 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'
));
@@ -223,7 +222,7 @@ function _output() {
*/
function __scaffoldView($params) {
if ($this->controller->_beforeScaffold('view')) {
-
+
$message = sprintf(__("No id set for %s::view()", true), Inflector::humanize($this->modelKey));
if (isset($params['pass'][0])) {
$this->ScaffoldModel->id = $params['pass'][0];
@@ -444,15 +443,15 @@ function __scaffold($params) {
$db = &ConnectionManager::getDataSource($this->ScaffoldModel->useDbConfig);
$prefixes = Configure::read('Routing.prefixes');
$scaffoldPrefix = $this->scaffoldActions;
-
+
if (isset($db)) {
if (empty($this->scaffoldActions)) {
$this->scaffoldActions = array(
'index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete'
);
} elseif (!empty($prefixes) && in_array($scaffoldPrefix, $prefixes)) {
$this->scaffoldActions = array(
- $scaffoldPrefix . '_index',
+ $scaffoldPrefix . '_index',
$scaffoldPrefix . '_list',
$scaffoldPrefix . '_view',
$scaffoldPrefix . '_add',
@@ -525,6 +524,10 @@ function __associations() {
$associations[$type][$assocKey]['controller'] =
Inflector::pluralize(Inflector::underscore($assocData['className']));
+
+ if ($type == 'hasAndBelongsToMany') {
+ $associations[$type][$assocKey]['with'] = $assocData['with'];
+ }
}
}
return $associations;
View
6 cake/libs/view/scaffolds/view.ctp
@@ -117,6 +117,10 @@ $otherSingularVar = Inflector::variable($_alias);
<tr>
<?php
$otherFields = array_keys(${$singularVar}[$_alias][0]);
+ if (isset($_details['with'])) {
+ $index = array_search($_details['with'], $otherFields);
+ unset($otherFields[$index]);
+ }
foreach ($otherFields as $_field) {
echo "\t\t<th>" . Inflector::humanize($_field) . "</th>\n";
}
@@ -130,7 +134,7 @@ $otherSingularVar = Inflector::variable($_alias);
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
- echo "\t\t<tr{$class}>\n";
+ echo "\t\t<tr{$class}>\n";
foreach ($otherFields as $_field) {
echo "\t\t\t<td>" . ${$otherSingularVar}[$_field] . "</td>\n";
View
12 cake/tests/cases/libs/controller/scaffold.test.php
@@ -155,9 +155,9 @@ class ScaffoldMock extends CakeTestModel {
var $hasAndBelongsToMany = array(
'ScaffoldTag' => array(
'className' => 'ScaffoldTag',
- 'foreignKey' => 'post_id',
- 'associationForeignKey' => 'tag_id',
- 'joinTable' => 'posts_tags'
+ 'foreignKey' => 'something_id',
+ 'associationForeignKey' => 'something_else_id',
+ 'joinTable' => 'join_things'
)
);
}
@@ -271,7 +271,7 @@ class ScaffoldViewTest extends CakeTestCase {
* @var array
* @access public
*/
- var $fixtures = array('core.article', 'core.user', 'core.comment', 'core.posts_tag', 'core.tag');
+ var $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
/**
* startTest method
@@ -459,6 +459,7 @@ function testViewScaffold() {
//check related table
$this->assertPattern('/<div class="related">\s*<h3>Related Scaffold Comments<\/h3>\s*<table cellpadding="0" cellspacing="0">/', $result);
$this->assertPattern('/<li><a href="\/scaffold_comments\/add">New Comment<\/a><\/li>/', $result);
+ $this->assertNoPattern('/<th>JoinThing<\/th>/', $result);
}
/**
@@ -659,7 +660,7 @@ class ScaffoldTest extends CakeTestCase {
* @var array
* @access public
*/
- var $fixtures = array('core.article', 'core.user', 'core.comment', 'core.posts_tag', 'core.tag');
+ var $fixtures = array('core.article', 'core.user', 'core.comment', 'core.join_thing', 'core.tag');
/**
* startTest method
*
@@ -741,6 +742,7 @@ function testScaffoldVariableSetting() {
$Scaffold =& new TestScaffoldMock($this->Controller, $params);
$result = $Scaffold->controller->viewVars;
+ $this->assertEqual($result['title_for_layout'], 'Scaffold :: Admin Edit :: Scaffold Mock');
$this->assertEqual($result['singularHumanName'], 'Scaffold Mock');
$this->assertEqual($result['pluralHumanName'], 'Scaffold Mock');
$this->assertEqual($result['modelClass'], 'ScaffoldMock');

0 comments on commit 39dd15d

Please sign in to comment.