Skip to content

Commit

Permalink
Fixing Helper::value() and extraction of habtm data. Refs #256
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 4, 2009
1 parent b974127 commit 380b49a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions cake/libs/view/helper.php
Expand Up @@ -544,7 +544,7 @@ function tagIsInvalid($model = null, $field = null, $modelID = null) {
$errors = $this->validationErrors;
$entity = $view->entity();
if (!empty($entity)) {
return Set::extract($errors,join('.',$entity));
return Set::extract($errors, join('.', $entity));
}
}

Expand Down Expand Up @@ -645,10 +645,18 @@ function value($options = array(), $field = null, $key = 'value') {

$view =& ClassRegistry::getObject('view');
$result = null;

$entity = $view->entity();
if (!empty($this->data) && !empty($entity)) {
$result = Set::extract($this->data,join('.',$entity));
$result = Set::extract($this->data, join('.', $entity));
}

$habtmKey = $this->field();
if (empty($result) && isset($this->data[$habtmKey]) && is_array($this->data[$habtmKey])) {
if (ClassRegistry::isKeySet($habtmKey)) {
$model =& ClassRegistry::getObject($habtmKey);
$result = $this->__selectedArray($this->data[$habtmKey], $model->primaryKey);
}
}

if (is_array($result)) {
Expand Down
4 changes: 2 additions & 2 deletions cake/tests/cases/libs/view/helper.test.php
Expand Up @@ -538,11 +538,11 @@ function testFieldSuffixForDate() {
*/
function testMulitDimensionValue() {
$this->Helper->data = array();
for($i = 0; $i < 2; $i++) {
for ($i = 0; $i < 2; $i++) {
$this->Helper->data['Model'][$i] = 'what';
$result[] = $this->Helper->value("Model.{$i}");
$this->Helper->data['Model'][$i] = array();
for($j = 0; $j < 2; $j++) {
for ($j = 0; $j < 2; $j++) {
$this->Helper->data['Model'][$i][$j] = 'how';
$result[] = $this->Helper->value("Model.{$i}.{$j}");
}
Expand Down

0 comments on commit 380b49a

Please sign in to comment.