<p>Try this:</p>
<pre><code>Craft::$app-&gt;getUrlManager()-&gt;setRouteParams([
               'variables' =&gt; ['order' =&gt; $order]
             ]);
</code></pre>

CC BY-SA 4.0
2021-02-08T22:28:17.323Z
2021-02-08T22:28:17.323Z
Nikolay Bronskiy
<p>I'm building out a Craft 3 plugin and can't see who to pass variables with redirection from a controller. </p>

<p>For example, I have a controller that I want to pass back to the defined redirect value along with a variable, eg:</p>

<p><code>return $this-&gt;redirectToPostedUrl( ['order' =&gt; $order ] );</code></p>

<p>However, trying to access the order variable within my template is returning empty. The order object definitely exists before the redirection as it can be accessed from within my controller.</p>

<p>Any suggestions appreciated - I'm sure am overlooking something quite straightforward!</p>

CC BY-SA 3.0
2018-05-01T16:11:34.420Z
Is it your own route? If so you can include the parameter to your URL rules or you can store it in the Session
Robin Schambach
CC BY-SA 3.0
2018-05-01T16:22:42.983Z
From digging through docs and code I take it setFlash and getFlash are no longer available? The only flash method I can seem to access are notice and error related
Cole Henley
CC BY-SA 3.0
2018-05-01T16:25:00.837Z
They still exists in the session component
Robin Schambach
CC BY-SA 3.0
2018-05-01T16:31:42.117Z
But I'd need my own variables to access this at a template level, correct?
Cole Henley
CC BY-SA 3.0
2018-05-01T16:33:32.087Z
What do you mean by "my own variables"?
Robin Schambach
CC BY-SA 3.0
2018-05-01T18:10:38.607Z
I mean write my own template variables to pull out anything passed as a session variable trough the redirect
Cole Henley
CC BY-SA 3.0
2018-05-01T18:12:03.900Z
Yes - this is correct. That's why I would suggest to include the parameter into the URL
Robin Schambach
<plugin-development><craft3><redirect><controller>
Plugin Development (Craft 3): Pass variables with redirection
# Plugin Development (Craft 3): Pass variables with redirection

(Asked by: username_0 on 2018-05-01)

I'm building out a Craft 3 plugin and can't see who to pass variables with redirection from a controller.

For example, I have a controller that I want to pass back to the defined redirect value along with a variable, eg:

`return $this->redirectToPostedUrl( ['order' => $order ] );`

However, trying to access the order variable within my template is returning empty. The order object definitely exists before the redirection as it can be accessed from within my controller.

Any suggestions appreciated - I'm sure am overlooking something quite straightforward!

**Tags:** plugin-development, craft3, redirect, controller
> **Comments:**
> **username_1**: Is it your own route? If so you can include the parameter to your URL rules or you can store it in the Session  
> **username_0**: From digging through docs and code I take it setFlash and getFlash are no longer available? The only flash method I can seem to access are notice and error related  
> **username_1**: They still exists in the session component  
> **username_0**: But I'd need my own variables to access this at a template level, correct?  
> **username_1**: What do you mean by "my own variables"?  
> **username_0**: I mean write my own template variables to pull out anything passed as a session variable trough the redirect  
> **username_1**: Yes - this is correct. That's why I would suggest to include the parameter into the URL  

---

## 1 answers

### Answer by username_2 on 2021-02-08. Score: 1

Try this:
Craft::$app->getUrlManager()->setRouteParams([
               'variables' => ['order' => $order]
             ]);


---

