A very important detail is that the asset function I created returns the full path to the static asset not the relative path from the php file position
What I have Done:
public static function asset($url){
$file_path = __DIR__.'/../../../resources/assets/'.$url;
$file_path = str_replace("\\","/",$file_path);
return $file_path;
}
in my index.php which contains html files:
<img width="500px" alt="<?php echo asset('images/image1.jpg');?>" src="<?php asset('images/image1.jpg');?>"/>
It gives me the correct full url to the file in the alt-property but no image is displayed.
It also does not work for css and javascript
The asset directory is
"__DIR__.'/../../../resources/assets/'.$url";
$url is the argument the user gives.
This is the returned file path on the html page:
c:/xampp/htdocs/project/app/Utilities/View/../../../resources/assets/images/image1.jpg
Is what is returned valid to be used as an image src in my index.php file???
__DIR__is the directory/path containing the file with your function definition. You probably don't want a system path here.