Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Paginator Component can work with requestAction() #1436

Closed
wants to merge 5 commits into from

4 participants

@zoghal

I'm not a lazy programmer. 3-hours hardly tried but did not succeed.
Please help me to implement the correct test.
I wanted to create like this test.: ( https://gist.github.com/zoghal/6032614
thanks

lib/Cake/Controller/Component/PaginatorComponent.php
@@ -238,7 +238,9 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
(array)$this->Controller->request['paging'],
array($object->alias => $paging)
);
-
+ if(!empty($this->Controller->request->params['requested'])) {

Code style error as reported by Travis:
https://travis-ci.org/cakephp/cakephp/jobs/9242562

241 | ERROR | Expected "if (...) {\n"; found "if(...) {\n"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Cake/Controller/Component/PaginatorComponent.php
@@ -309,12 +311,16 @@ protected function _getObject($object) {
*/
public function mergeOptions($alias) {
$defaults = $this->getDefaults($alias);
+ $request = $this->Controller->request;
+ if(!empty($request->params['requested'])) {

Code style error as reported by Travis:
https://travis-ci.org/cakephp/cakephp/jobs/9242562

315 | ERROR | Expected "if (...) {\n"; found "if(...) {\n"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Cake/Controller/Component/PaginatorComponent.php
@@ -309,12 +311,16 @@ protected function _getObject($object) {
*/
public function mergeOptions($alias) {
$defaults = $this->getDefaults($alias);
+ $request = $this->Controller->request;
+ if(!empty($request->params['requested'])) {
+ $request = Router::getRequest();
+ }
@markstory Owner

Couldn't you always use the controller request? That request object should be passed into the view as well.

@zoghal
zoghal added a note

Requested by requestAction is generated, it does not handle any of the current controller parameters (named, pass). Actually creates a new request, and after receiving the request object is deleted.
So the Router :: getRequest () are used to access the requested controller

        if (is_string($url)) {
            $request = new CakeRequest($url);
        } elseif (is_array($url)) {
            $params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
            $params = array_merge($params, $extra);
            $request = new CakeRequest(Router::reverse($params));
        }
        if (isset($data)) {
            $request->data = $data;
        }

        $dispatcher = new Dispatcher();
        $result = $dispatcher->dispatch($request, new CakeResponse(), $extra);
        Router::popRequest();
        return $result;
@markstory Owner

Yes this occurs because you're supposed to include the various passed/named parameters into the requestAction url. The current request parameters are intentionally not supposed to bleed into sub-requests.

It sounds like you were expecting parameters to bleed between requests. Which is the opposite of what should be happening.

@ADmad Collaborator
ADmad added a note

Looking at the gist too it does seem he expects the named params to bleed through which is wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@zoghal zoghal closed this
@zoghal zoghal deleted the zoghal:reqestAction-Paginator branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 4 deletions.
  1. +9 −4 lib/Cake/Controller/Component/PaginatorComponent.php
View
13 lib/Cake/Controller/Component/PaginatorComponent.php
@@ -230,7 +230,6 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
'options' => Hash::diff($options, $defaults),
'paramType' => $options['paramType']
);
-
if (!isset($this->Controller->request['paging'])) {
$this->Controller->request['paging'] = array();
}
@@ -238,7 +237,9 @@ public function paginate($object = null, $scope = array(), $whitelist = array())
(array)$this->Controller->request['paging'],
array($object->alias => $paging)
);
-
+ if (!empty($this->Controller->request->params['requested'])) {
+ Router::getRequest()->params['paging'] = $this->Controller->request['paging'];
+ }
if (
!in_array('Paginator', $this->Controller->helpers) &&
!array_key_exists('Paginator', $this->Controller->helpers)
@@ -309,12 +310,16 @@ protected function _getObject($object) {
*/
public function mergeOptions($alias) {
$defaults = $this->getDefaults($alias);
+ $request = $this->Controller->request;
+ if (!empty($request->params['requested'])) {
+ $request = Router::getRequest();
+ }
switch ($defaults['paramType']) {
case 'named':
- $request = $this->Controller->request->params['named'];
+ $request = $request->params['named'];
break;
case 'querystring':
- $request = $this->Controller->request->query;
+ $request = $request->query;
break;
}
$request = array_intersect_key($request, array_flip($this->whitelist));
Something went wrong with that request. Please try again.