1

everybody!

setRouteVariables() doesn't appear to be working for me. If I boil my controller function down to just this:

public function actionSubmitForm() {
    craft()->urlManager->setRouteVariables([
        'foo' => 'bar'
    ]);
}

and my <form method="post" action="" accept-charset="UTF-8"> contains the following (among other inputs):

<input type="hidden" name="action" value="directoryForms/submitForm">

it hits the correct endpoint and then reloads the appropriate template, but it doesn't give me access to the {{ foo }} variable in that template. It just tells me Variable "foo" does not exist. I know it's hitting the right controller endpoint because if I die() there it dies as expected.

Any thoughts? I've really boiled this one down as far as I can. I must be missing something obvious. Thanks!

  • Just a guess, but something else (another plugin?) is redirecting/interfering with the request of the request and not letting it continue as you're expecting? – Brad Bell Jan 31 '17 at 5:14
  • Ah, I do have custom routes set for this plugin via registerSiteRoutes()! How does that change how I proceed? I'd like to pass these variables back through that custom site route. (My full use case is filling in bad user input on validation failure) – Billy Pilgrim Jan 31 '17 at 13:36
  • Alrighty, I've got it now. Thanks for the push in the right directory, Brad. I ended up routing directly to a template rather than an action which loads a template. I didn't even realize that could be done! – Billy Pilgrim Jan 31 '17 at 14:16
  • Would you mind adding what worked for you as an official answer in case it ends up helping someone else in the future? – Brad Bell Jan 31 '17 at 18:22
  • Of course! Thanks for all you do in the community, Brad. – Billy Pilgrim Jan 31 '17 at 19:19
1

My solution was to load the template directly rather than routing to the controller first. Essentially, in my registerSiteRoutes() function I replaced this:

"payment" => ['action' => 'someController/doPayment']

with

"payment" => 'templateDir/core/payment'

I didn't even realize you could do this in registerSiteRoutes()!

| improve this answer | |

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.