Updating methods in Helper to use $this->_View.

This commit is contained in:
mark_story 2010-07-14 22:35:36 -04:00
parent 7efe1636aa
commit 7b3f2f7e6e

View file

@ -428,8 +428,7 @@ class Helper extends Object {
* @return void * @return void
*/ */
public function setEntity($entity, $setScope = false) { public function setEntity($entity, $setScope = false) {
$view =& ClassRegistry::getObject('view'); $view =& $this->_View;
if ($setScope) { if ($setScope) {
$view->modelScope = false; $view->modelScope = false;
} elseif (!empty($view->entityPath) && $view->entityPath == $entity) { } elseif (!empty($view->entityPath) && $view->entityPath == $entity) {
@ -573,11 +572,10 @@ class Helper extends Object {
* @return string * @return string
*/ */
public function model() { public function model() {
$view =& ClassRegistry::getObject('view'); if (!empty($this->_View->association)) {
if (!empty($view->association)) { return $this->_View->association;
return $view->association;
} else { } else {
return $view->model; return $this->_View->model;
} }
} }
@ -587,8 +585,7 @@ class Helper extends Object {
* @return mixed * @return mixed
*/ */
public function modelID() { public function modelID() {
$view =& ClassRegistry::getObject('view'); return $this->_View->modelId;
return $view->modelId;
} }
/** /**
@ -597,8 +594,7 @@ class Helper extends Object {
* @return string * @return string
*/ */
public function field() { public function field() {
$view =& ClassRegistry::getObject('view'); return $this->_View->field;
return $view->field;
} }
/** /**
@ -611,9 +607,8 @@ class Helper extends Object {
* @return boolean True on errors. * @return boolean True on errors.
*/ */
public function tagIsInvalid($model = null, $field = null, $modelID = null) { public function tagIsInvalid($model = null, $field = null, $modelID = null) {
$view =& ClassRegistry::getObject('view');
$errors = $this->validationErrors; $errors = $this->validationErrors;
$entity = $view->entity(); $entity = $this->_View->entity();
if (!empty($entity)) { if (!empty($entity)) {
return Set::extract($errors, join('.', $entity)); return Set::extract($errors, join('.', $entity));
} }
@ -631,8 +626,6 @@ class Helper extends Object {
* @todo Refactor this method to not have as many input/output options. * @todo Refactor this method to not have as many input/output options.
*/ */
public function domId($options = null, $id = 'id') { public function domId($options = null, $id = 'id') {
$view =& ClassRegistry::getObject('view');
if (is_array($options) && array_key_exists($id, $options) && $options[$id] === null) { if (is_array($options) && array_key_exists($id, $options) && $options[$id] === null) {
unset($options[$id]); unset($options[$id]);
return $options; return $options;
@ -641,7 +634,7 @@ class Helper extends Object {
return $this->domId(); return $this->domId();
} }
$entity = $view->entity(); $entity = $this->_View->entity();
$model = array_shift($entity); $model = array_shift($entity);
$dom = $model . join('', array_map(array('Inflector', 'camelize'), $entity)); $dom = $model . join('', array_map(array('Inflector', 'camelize'), $entity));
@ -667,7 +660,6 @@ class Helper extends Object {
* @todo Refactor this method to not have as many input/output options. * @todo Refactor this method to not have as many input/output options.
*/ */
protected function _name($options = array(), $field = null, $key = 'name') { protected function _name($options = array(), $field = null, $key = 'name') {
$view =& ClassRegistry::getObject('view');
if ($options === null) { if ($options === null) {
$options = array(); $options = array();
} elseif (is_string($options)) { } elseif (is_string($options)) {
@ -688,7 +680,7 @@ class Helper extends Object {
$name = $field; $name = $field;
break; break;
default: default:
$name = 'data[' . implode('][', $view->entity()) . ']'; $name = 'data[' . implode('][', $this->_View->entity()) . ']';
break; break;
} }
@ -727,11 +719,9 @@ class Helper extends Object {
if (!empty($field)) { if (!empty($field)) {
$this->setEntity($field); $this->setEntity($field);
} }
$view =& ClassRegistry::getObject('view');
$result = null; $result = null;
$entity = $view->entity(); $entity = $this->_View->entity();
if (!empty($this->data) && !empty($entity)) { if (!empty($this->data) && !empty($entity)) {
$result = Set::extract($this->data, join('.', $entity)); $result = Set::extract($this->data, join('.', $entity));
} }
@ -747,8 +737,8 @@ class Helper extends Object {
} }
if (is_array($result)) { if (is_array($result)) {
if (array_key_exists($view->fieldSuffix, $result)) { if (array_key_exists($this->_View->fieldSuffix, $result)) {
$result = $result[$view->fieldSuffix]; $result = $result[$this->_View->fieldSuffix];
} }
} }