02-04-2016, 03:28 AM
I am using the codeIgniter directory helper but have small question.
When I display my images and directory's in my foreach loop $image variable is a directory it throws error.
Error Message: Array to string conversion I have attached image of error.
As shown in var dump sub folder is directory but when I echo out the foreach loop it throws error for that directory.
Any suggestion I need to display sub directory and images. Images I can display fine
View
When I display my images and directory's in my foreach loop $image variable is a directory it throws error.
Error Message: Array to string conversion I have attached image of error.
PHP Code:
array (size=5)
0 => string 'codeigniter.png' (length=15)
1 => string 'CSS-Tricks-1024x469.png' (length=23)
2 => string 'IMG_20151230_154130.jpg' (length=23)
3 => string 'preypay.png' (length=11)
'subfolder\' =>
array (size=0)
empty
As shown in var dump sub folder is directory but when I echo out the foreach loop it throws error for that directory.
Any suggestion I need to display sub directory and images. Images I can display fine
PHP Code:
<?php
class Filemanager extends CI_Controller {
public function index() {
$this->load->helper('directory');
$data['images'] = array();
// Finds and loads images and directorys.
$images = directory_map('./images/catalog/', FALSE, TRUE);
var_dump($images);
foreach($images as $image) {
$data['images'][] = array(
'img' => $image
);
}
$this->load->view('filemanager_view', $data);
}
}
View
PHP Code:
<div class="container" style="margin-top: 20px;">
<div class="row">
<?php if ($images) {?>
<?php foreach ($images as $image) {?>
<div class="col-lg-3">
<a class="thumbnail">
<?php echo $image['img'];?>
</a>
<div class="caption text-center">
</div>
</div>
<?php }?>
<?php } else {?>
<div class="col-lg-12 col-md-12 col-sm-12">
<h3>No images available</h3>
</div>
<?php }?>
</div>
</div>
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!