Answers.Body: <p>Try this:</p>
  <pre><code>Craft::$app-&gt;getUrlManager()-&gt;setRouteParams([
                 'variables' =&gt; ['order' =&gt; $order]
               ]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-02-08T22:28:17.323Z
Answers.LastActivityDate: 2021-02-08T22:28:17.323Z
Answers.UserDisplayName: Nikolay Bronskiy
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-05-01T16:11:34.420Z
Comments.Text: Is it your own route? If so you can include the parameter to your URL rules or you can store it in the Session
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-05-01T16:22:42.983Z
Comments.Text: 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
Comments.UserDisplayName: Cole Henley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-05-01T16:25:00.837Z
Comments.Text: They still exists in the session component
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-05-01T16:31:42.117Z
Comments.Text: But I'd need my own variables to access this at a template level, correct?
Comments.UserDisplayName: Cole Henley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-05-01T16:33:32.087Z
Comments.Text: What do you mean by "my own variables"?
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-05-01T18:10:38.607Z
Comments.Text: I mean write my own template variables to pull out anything passed as a session variable trough the redirect
Comments.UserDisplayName: Cole Henley
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-05-01T18:12:03.900Z
Comments.Text: Yes - this is correct. That's why I would suggest to include the parameter into the URL
Comments.UserDisplayName: Robin Schambach
Tags: <plugin-development><craft3><redirect><controller>
Title: Plugin Development (Craft 3): Pass variables with redirection
ThreadText: # 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]
               ]);
  
  ```
  
  
  ---
  
  