I'm building my first MVC project and I need some help. I need to display image with 2 links previous
and next
. So here is what I've done
Controller
function nextImg(){
$id = $this -> setImgId();
$size = $this -> setImgSize();
$nbimg = $this -> setImgNb();
$id= $this->ImageDAO->getNextImage($id);
$img_path = $this->ImageDAO->getMultipleImg($id, $nbimg);
require_once("view/viewPhoto.php");
}
Model
public function getMultipleImg($id, $nbimg) {
if($id == null){
$id=1;
}
$s = $this->db->query('SELECT path FROM image LIMIT '.$id.', '.$nbimg.'');
$res = $s->fetchAll();
for($i=0;$i<count($res);$i++){
$list[$i] = $res[$i]['path'];
}
return $list;
}
function getNextImage($id) {
$id = $id+1;
return $id;
}
View
for($i=0; $i<count($img_path); $i++)
{
print "<img src=\"$img_path[$i]\" width=\"$size\" height=\"$size\">
";
}
print "<li><a href=\"?controller=Display&id=".$id."&size=".$size."&nbimg=".$nbimg."&action=prevImg\">prev</a></li>
";
print "<li><a href=\"?controller=Display&id=".$id."&size=".$size."&nbimg=".$nbimg."&action=nextImg\">next</a></li>
";
The problem is that when I click the next or previous button, the ID in the URL is the ID of the image previously displayed. Where the problem comes from ?
I think the first three lines are supposed to be getters not setters:
$id = $this -> getImgId();
$size = $this -> getImgSize();
$nbimg = $this -> getImgNb();