"Refactoring Controller::paginate()"

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6105 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-12-02 22:58:23 +00:00
parent a61b32c91e
commit 61eebea0f4
2 changed files with 23 additions and 17 deletions

View file

@ -853,34 +853,34 @@ class Controller extends Object {
}
$assoc = null;
if (is_string($object) && !strpos($object, '.')) {
if (isset($this->{$object})) {
if (is_string($object)) {
$assoc = null;
if (strpos($object, '.') !== false) {
list($object, $assoc) = explode('.', $object);
}
if ($assoc && isset($this->{$object}->{$assoc})) {
$object = $this->{$object}->{$assoc};
} elseif ($assoc && isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$assoc})) {
$object = $this->{$this->modelClass}->{$assoc};
} elseif (isset($this->{$object})) {
$object = $this->{$object};
} elseif (isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$object})) {
$object = $this->{$this->modelClass}->{$object};
} elseif (!empty($this->uses)) {
for ($i = 0; $i < count($this->uses); $i++) {
$model = $this->uses[$i];
if (isset($this->{$model}->{$object})) {
$object = $this->{$model}->{$object};
break;
}
}
}
} elseif (is_string($object)) {
list($object, $assoc) = explode('.', $object);
if (isset($this->{$object})) {
$object = $this->{$object};
}
} elseif (empty($object) || $object == null) {
if (isset($this->{$this->modelClass})) {
$object = $this->{$this->modelClass};
} else {
$className = null;
if (strpos($this->uses[0], '.') !== false) {
list($plugin, $className) = explode('.', $this->uses[0]);
list($name, $className) = explode('.', $this->uses[0]);
}
if ($className) {
$object = $this->{$className};
} else {
$object = $this->{$this->uses[0]};
$object = $this->{$name};
}
}
}

View file

@ -86,6 +86,12 @@ class ControllerTest extends CakeTestCase {
$Controller->constructClasses();
$Controller->modelClass = null;
$results = Set::extract($Controller->paginate('ControllerPost'), '{n}.ControllerPost.id');
$this->assertEqual($results, array(1, 2, 3));
$results = Set::extract($Controller->paginate('ControllerComment'), '{n}.ControllerComment.id');
$this->assertEqual($results, array(1, 2, 3, 4, 5, 6));
$Controller->uses[0] = 'Plugin.ControllerPost';
$results = Set::extract($Controller->paginate(), '{n}.ControllerPost.id');
$this->assertEqual($results, array(1, 2, 3));