I have been trying to debug this code for a while now, and it looks like the build
method is not being called. I put echo's, var_dumps, and all other kinds of signs in it, but never get anything.
Full php code
class Auto_slideshow {
private $_img_dir;
//constructor sets directory containing the images
function __construct($dir) {
//Directory source from webroot
$_img_dir = $dir;
}
//Iterates through directory and constructs HTML img list
public function build() {
//use SPL for directory iteration
$iterator = new DirectoryIterator($_img_dir);
$html = '';
$i = 1;
//Iterate through directory
foreach ($iterator as $file) {
//set a variable to add class of "show" on first element
$showClass = $i === 1 ? ' class="show"' : null;
//exclude '.' and '..' files
if(!$iterator->isDot()) {
//set src attribute for img tag
$src = $_img_dir . $iterator->getFilename();
//Grab sizes of images
$size = getimagesize($_img_dir . $iterator->getFilename());
var_dump($src);
//create img tags
$html .= '<img src="' . $src . '" ' . $size[3] . $displayNone . ' />' . "
";
$i++;
}
}
return $html;
}
}
html call
<center>
<div class="imagecontainer" id="auto-slideshow">
<?php
$show = new Auto_slideshow("../CMSC/images/master/slidestock/");
$show->build();
?>
</div>
</center>
I also tried print $show->build();
, as the tutorial showed, which also did not work.
Update
I changed $_img_dir
to $this->$_img_dir' and called the method by
echo show->build();` and the method still isn't being called.
This is a matter of the method not even running, not even to the point of find the images yet.
Update 2
If I remove the entire php code within the html, the rest of the page loads just fine. As it is now, the html loads only to the div that contains the php then stop everything after it.