1

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!

7
  • Is it your own route? If so you can include the parameter to your URL rules or you can store it in the Session May 1 '18 at 16:11
  • 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 May 1 '18 at 16:22
  • They still exists in the session component May 1 '18 at 16:25
  • 1
    But I'd need my own variables to access this at a template level, correct? May 1 '18 at 16:31
  • What do you mean by "my own variables"? May 1 '18 at 16:33
1

Try this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.