public function index()
{
//TODO: extract code below from controller :)
$manuals = [];
$filesInFolder = \File::files('manual');
foreach($filesInFolder as $path)
{
$manuals[] = pathinfo($path);
}
return View::make('manuals.index')->with('manuals', $manuals);
}
pathinfo gives you:
{
"dirname":"file_path",
"basename":"file_name.file_extension",
"extension":"file_extension",
"filename":"file_name"
}
I pretty much need something like this, but whatever I try it just gives me the following error:
htmlspecialchars() expects parameter 1 to be string, array given
in your view you're probably trying to echo an array instead of a string.
RafaelDeJongh said:
I pretty much need something like this, but whatever I try it just gives me the following error:
htmlspecialchars() expects parameter 1 to be string, array given
astroanu said:
in your view you're probably trying to echo an array instead of a string.
RafaelDeJongh said:
I pretty much need something like this, but whatever I try it just gives me the following error:
htmlspecialchars() expects parameter 1 to be string, array given
Seems it had to do something regarding the whole parameters of the array being $files[$file]["dirname"] rather than $files[$file][0]
And the key that I had to set for the foreach also seemed to mess things around a bit more.
Currently have this setup to loop through all the files in a given directory:
@foreach($files as $file=>$f)
@php($filePath=$files[$file]["dirname"]."\\".$files[$file]["basename"])
<a href="{{$filePath}}" title="{{url('/')}}\{{$filePath}}" class="recImg"><img src="{{$filePath}}" alt="{{$files[$file]['filename']}}"/></a>
@endforeach
Any suggestions would be welcomed as I'm pretty new to all of this :)
I would create a collection and map the urls in the controller before sending that to the view.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community