Query parameter string in cakePHP 3.4


I’m getting null query parameter string even though passing query parameter string like this login?redirect=%2Farticles%2Fadd.
I have tried to retrieve by using $this->request->getQuery(‘redirect’); and $this->request->query(‘redirect’);
Does anyone have any idea that where it would be wrong?


@ashok Looks like you are not setup your Url Route properly in your config/routes.php file. when you are interested to pass any route parameter to your controller action you should config your route proper way. although your question is not written detailedly.

i hope you will get much more information from this articles.


Thank you.


Sorry I’m new to cakephp… I’m setting up Url route like below,

  Router::scope('/', function ($routes) {
            ['controller' => 'Users', 'action' => 'view'],
                'pass' => ['id', 'slug'],
                'id' => '[0-9]+'

Router::scope('/', function ($routes) {
        ['controller' => 'Users', 'action' => 'login'],
            'pass' => ['slug']

is there any wrong with this?


First of all why you are sending a query string for redirecting, just follow the standard ways as given in CakePHP docs.


hi that 's the standard way to redirect to current page after loggedin in cakephp 3.4, according to this docs


that’s why i’m trying to retrieve query parameter.


The loginRedirect rule means something like mentioned over here.



If you get null, it’s only because your route doesn’t match the route received. What is the result of debug after you log in your system ?

<?= debug($this->request) ?>

And then, this is how I manage the redirect with cake:

            if (isset($this->request->query['redirect']) && !empty($this->request->query['redirect'])) {