As documented here I can read my image files in view by using following code.
<img src="<?php echo $view['assets']->getUrl('images/logo.png') ?>" alt="Symfony!" />
//// This outputs the image
or I can also do
<?php
echo $view['assets']->getUrl('images/logo.png');
// echoes ---> /assets/images/logo.png
?>
However, my views are much complex and I want to divide different sections of view in functions. So when I write the above code in a function, it 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: Call to a member function getUrl() on a non-object in ....\Resources\views\Section\splash.html.php on line 12
Can someone please guide me how can I get this to work?
This is my full 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 is how I am calling the view from my controller
return $this->render('MySimpleBundle:Section:splash.html.php');