# Query parameter string in cakePHP 3.4

**URL:** https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636
**Category:** Need Help
**Created:** [May 30, 2017, 5:39pm UTC](https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636 "2017-05-30T17:39:01Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ashok](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@ashok](https://discourse.cakephp.org/u/ashok)
#### Post date: [May 30, 2017, 5:39pm UTC](https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636/1 "2017-05-30T17:39:01Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![rahadur](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rahadur/32/595_2.png) [@rahadur](https://discourse.cakephp.org/u/rahadur)
#### Post date: [May 30, 2017, 7:59pm UTC](https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636/2 "2017-05-30T19:59:12Z")

</div>

@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.

[https://book.cakephp.org/3.0/en/development/routing.html#passing-parameters-to-action](https://book.cakephp.org/3.0/en/development/routing.html#passing-parameters-to-action)

Thank you.

---

<div class="post-metadata">

### Author: ![ashok](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@ashok](https://discourse.cakephp.org/u/ashok)
#### Post date: [May 31, 2017, 3:32am UTC](https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636/3 "2017-05-31T03:32:43Z")

</div>

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

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

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

```

is there any wrong with this?

---

<div class="post-metadata">

### Author: ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)
#### Post date: [May 31, 2017, 3:52am UTC](https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636/4 "2017-05-31T03:52:50Z")

</div>

First of all why you are sending a query string for redirecting, just follow the standard ways as given in [CakePHP docs](https://book.cakephp.org/3.0/en/controllers.html#redirecting-to-other-pages).

---

<div class="post-metadata">

### Author: ![ashok](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@ashok](https://discourse.cakephp.org/u/ashok)
#### Post date: [May 31, 2017, 5:18am UTC](https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636/5 "2017-05-31T05:18:04Z")

</div>

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

[https://book.cakephp.org/3.0/en/controllers/components/authentication.html#redirecting-users-after-login](https://book.cakephp.org/3.0/en/controllers/components/authentication.html#redirecting-users-after-login)

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

---

<div class="post-metadata">

### Author: ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)
#### Post date: [May 31, 2017, 5:26am UTC](https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636/6 "2017-05-31T05:26:42Z")

</div>

The loginRedirect rule means something like mentioned over [here](https://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html#authentication-login-and-logout).

---

<div class="post-metadata">

### Author: ![Speudyland](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/speudyland/32/569_2.png) [@Speudyland](https://discourse.cakephp.org/u/Speudyland)
#### Post date: [June 2, 2017, 8:16am UTC](https://discourse.cakephp.org/t/query-parameter-string-in-cakephp-3-4/2636/7 "2017-06-02T08:16:31Z")

</div>

Hi,

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'])) {
> $this->redirect($this->request->query['redirect'],302);
> }
> 
> ```

🙂
