Adding fix for Controller::paginate() when default model is loaded from a plugin (Ticket #3660)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6098 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-11-30 22:27:43 +00:00
parent ba59fad873
commit 00dc6dedb5
2 changed files with 20 additions and 1 deletions

View file

@ -875,10 +875,15 @@ class Controller extends Object {
} elseif (empty($object) || $object == null) { } elseif (empty($object) || $object == null) {
if (isset($this->{$this->modelClass})) { if (isset($this->{$this->modelClass})) {
$object = $this->{$this->modelClass}; $object = $this->{$this->modelClass};
} else {
if (strpos($this->uses[0], '.') !== false) {
list($plugin, $className) = explode('.', $this->uses[0]);
$object = $this->{$className};
} else { } else {
$object = $this->{$this->uses[0]}; $object = $this->{$this->uses[0]};
} }
} }
}
if (!is_object($object)) { if (!is_object($object)) {
trigger_error(sprintf(__('Controller::paginate() - can\'t find model %1$s in controller %2$sController', true), $object, $this->name), E_USER_WARNING); trigger_error(sprintf(__('Controller::paginate() - can\'t find model %1$s in controller %2$sController', true), $object, $this->name), E_USER_WARNING);

View file

@ -77,5 +77,19 @@ class ControllerTest extends CakeTestCase {
unset($Controller); unset($Controller);
} }
function testPaginate() {
$Controller =& new Controller();
$Controller->uses = array('ControllerPost', 'ControllerComment');
$Controller->passedArgs[] = '1';
$Controller->params['url'] = array();
$Controller->constructClasses();
$Controller->modelClass = null;
$Controller->uses[0] = 'Plugin.ControllerPost';
$results = Set::extract($Controller->paginate(), '{n}.ControllerPost.id');
$this->assertEqual($results, array(1, 2, 3));
} }
}
?> ?>