I need to send the URL of a Drupal 8 route to a template. I read some documentation on Drupal API, but when I implement this in my module, nothing happens.
My route in my routing file looks like the following.
movies.addMovie:
path: /movies/add/{system}/{id}
defaults:
_controller: 'Drupal\movies\Controller\InsertController:addMovie'
_title: 'Add Movie'
system: ''
id: ''
requirements:
_permission: 'create movies_movie'
This is the code I am using to get the URL from the route.
use Drupal\Core\Url;
Url::fromRoute('movies.addMovie')
When I put the URL in a variable, the code stops when calling Url::fromRoute()
. Can someone tell me what I'm doing wrong?
url()
-- you should use that inside twig. If you're set on usingUrl::fromRoute()
, then you probably want to call Url::toString() on the returned Url object. Like:$url_string = Url::fromRoute('add.movie')->toString();
– aaronbauman Jan 9 '17 at 17:26