php - Symfony2: How to get asset's URL in function inside view template -



php - Symfony2: How to get asset's URL in function inside view template -

as documented here can read image files in view using next code.

<img src="<?php echo $view['assets']->geturl('images/logo.png') ?>" alt="symfony!" /> //// outputs image

or can do

<?php echo $view['assets']->geturl('images/logo.png'); // echoes ---> /assets/images/logo.png ?>

however, views much complex , want split different sections of view in functions. when write above code in function, doesn't work.

function one(){ echo $view['assets']->geturl('images/logo.png'); } one(); notice: undefined variable: view in ....\resources\views\section\splash.html.php on line 12 fatal error: phone call fellow member function geturl() on non-object in ....\resources\views\section\splash.html.php on line 12

can please guide me how can work?

this total view file.

<?php echo $view['assets']->geturl('images/logo.png') . "<br><br>"; function one(){ echo $view['assets']->geturl('images/logo.png') . "<br><br>"; } one(); ?> <img src="<?php echo $view['assets']->geturl('images/logo.png') ?>" alt="no image" />

this how calling view controller

return $this->render('mysimplebundle:section:splash.html.php');

the function "one()" has own variable scope, have pass url function http://php.net/manual/en/language.variables.scope.php

function one($url) { echo $view['assets']->geturl($url) . "<br><br>"; }

anyway, in sentiment should utilize simply:

<img src="<?php echo $view['assets']->geturl('images/logo.png') ?>" alt="symfony!" />

to render image, if view gets complex, may right time switch powerful templating engine twig

php symfony2 twig

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -