PBR
PBR

Reputation: 316

Can't find image path inside Symfony controller

Inside my Symfony2/web/img directory is a file del.png which i want to display from within a controller.

I tried using functions like image_path() of image_tag() but Symfony tells me this are unknown functions...

It can be done with:

$html = "<img src='".$request->getBasePath()."/img/del.png' alt='Delete user' border=0>";
return $this->render ('myBundle:stats:menu.html.twig', array('html'=>$html));

or also like stated in Symfony2 Assetic get asset urls from inside controller, not template

but I think it can be done an easier way. It seems sooo simple, so i'm probably forgetting something :-( Any suggestions?

Upvotes: 0

Views: 2032

Answers (2)

PBR
PBR

Reputation: 316

You can do this like:

$this->container->get('templating.helper.assets')->getUrl('img/edit.png')

Upvotes: 2

Mario Radomanana
Mario Radomanana

Reputation: 1698

Use assetic function

echo '<img src="'.$view['assets']->getUrl('img/del.png').'" alt="Delete user" border="0">';

Upvotes: 1

Related Questions