From 00dc6dedb58938491203530fef3994a5de672807 Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 30 Nov 2007 22:27:43 +0000 Subject: [PATCH] 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 --- cake/libs/controller/controller.php | 7 ++++++- .../cases/libs/controller/controller.test.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index 766d363d5..67eadce1f 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -876,7 +876,12 @@ class Controller extends Object { if (isset($this->{$this->modelClass})) { $object = $this->{$this->modelClass}; } else { - $object = $this->{$this->uses[0]}; + if (strpos($this->uses[0], '.') !== false) { + list($plugin, $className) = explode('.', $this->uses[0]); + $object = $this->{$className}; + } else { + $object = $this->{$this->uses[0]}; + } } } diff --git a/cake/tests/cases/libs/controller/controller.test.php b/cake/tests/cases/libs/controller/controller.test.php index 833535e5a..cd0b46303 100644 --- a/cake/tests/cases/libs/controller/controller.test.php +++ b/cake/tests/cases/libs/controller/controller.test.php @@ -77,5 +77,19 @@ class ControllerTest extends CakeTestCase { 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)); + } } + ?> \ No newline at end of file