getQuery('page') = null in cakephp 3.6

Hello,

// URL is /Personas/index?page=1&sort=title
$page = $this->request->getQuery('page');

It makes me null and void all the time.

in Controller:

public function index() {
$page = $this->request->getQuery('page');
}

in Routes:
$routes->connect('/index/*', ['controller' => 'Personas', 'action' => 'index']);

link:
/Personas/index?page=5

With sort or any other parameter passed through url does nothing, this only happens to me with pagination.

1 Like

I can’t replicate your problem in Cakephp 3.8.5

If you do $this->request->getQueryParams() can you confirm that the value is present?

Controller:

$params = $this->request->getQueryParams();
      debug($params);
      print_r($params);
      die();

result:

**/src/Controller/PersonasController.php** (line **236** )
[]
Array ( )

did you try `bin/cake routes check ‘/Personas/index?page=1&sort=title’ to see how your router is handling the url?

How do I check in Routes the url that comes to him? I usually do that in the controller through a debug($page) for example;

If I put by hand the url in the browser for example:

/Personas/index?page=5&sort=name’.

It doesn’t go to page 5 and it doesn’t sort by name.

Instead it shows page 1 and sorts by the ID that are the default values.

You’ll need to use the console tools from the command line

https://book.cakephp.org/4/en/console-commands.html

and specifically these:

https://book.cakephp.org/4/en/console-commands/routes.html

oohh thank you! I’m going to try

bin/cake routes check "Personas/index?page=2"

pass this empty

Try disable or comment your put line on routes…

If I comment on the line of routes it does the same, but the directions instead of creating them as:

Personas/index?page=2

It creates them without the index:

Personas?page=2

1 Like

The problem was in the configuration of Nginx, in:

location / {

I just had to change this line:

try_files $uri $uri/ /index.php;

for this one:

try_files $uri /index.php?$args;

and it all worked.