Reputation: 544
I wanted to send generated links from my controller to jquery, but it doesn't work because of the function : path, I made like this:
$html = '<a href="{{ path("cs_Content", {"tId": "'.$tnum.'"}) }}">'.$tname.'...</a>';
Question Is this right how i wrote or should I write the link without path?
Upvotes: 0
Views: 54
Reputation: 10085
path
is a twig function. In controller you have to use php functions of course:
$html = sprintf('<a href="%s">%s</a>', $this->generateUrl('cs_content', array('tId' => $tnum), UrlGeneratorInterface::ABSOLUTE_URL), $tname);
Here I generate an absolute url, because it's more save to use absolute urls in client side (struggled with relatives url in past from time to time ;)
Upvotes: 1
Reputation: 568
You're mixing Twig and php notation.
$link = $this->generateUrl('cs_Content', array(
'tId' => $tnum,
));
$html = '<a href="' . $link . '">'.$tname.'...</a>';
Upvotes: 1