You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 20, 2026. It is now read-only.
jszanto edited this page Aug 30, 2016
·
1 revision
If you need to create dynamic routes within JavaScript code, we have the
JavaScript URL Helper for that. Here we have two components.
First, to be able to use a route in JavaScript code, you need to tell the
ScriptUrl view helper to expose that URL to the JavaScript URL helper. You do
this in the view where you need the JavaScript URL helper. For example:
<?php// for a route `home` without any parameters$this->scriptUrl()->requireUrl('home');
// for a route `activity/show` with a parameter `id`$this->scriptUrl()->requireUrl('activity/show', ['id']);
Now, in JavaScript code (even in *.js files), you can use these routes
almost like you are using the normal URL view helper:
text='<a href="'+URLHelper.url('home')+'">';// or with parameters:text='<a href="'+URLHelper.url('activity/show',{id: 32})+'">';