Support the ongoing development of Laravel.io →
posted 10 years ago
Views Blade
Last updated 2 years ago.
0
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"
}
Last updated 2 years ago.
0

Awesome, thanks for quick answer!

Last updated 2 years ago.
0

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

Last updated 7 years ago.
0

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

0

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 :)

0

I would create a collection and map the urls in the controller before sending that to the view.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Jecode jecode Joined 24 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.