0

I would like to recover a road with URL::FromRoute Except that I have some concerns when I use to toString

$path = Url::fromRoute('my_route_name',['mypParamsId' =>  'MYPARAMSID'])->toString();

In this way I find a road but it's not the right one

I wish I could recover that

$path = Url::fromRoute('my_route_name',['mypParamsId' =>  '{MYPARAMSID}'])->toString();

But when I use the toString it does not work and Drupal cannot access my route and if I remove the String it returns my object to me without error

2 Answers2

1

Try this:

$myurl = Url::fromRoute('my_route_name',['mypParamsId' =>  $theValue]);
$link = \Drupal::service(‘link_generator’)->generate(‘title’, $myurl);

Then print $myurl Because, it implements _toString()

Or Using Drupal\Core\Link for the 2nd line

$url = Url::fromRoute('myrouteName', array(
          'My_id' => $item->id
    ));

$link= Link::fromTextAndUrl($item->id, $url);
salah-1
  • 1,299
  • 11
  • 15
0
$current_path = Url::fromRoute('<current>', [], ['absolute' => 'true']);