class home
{
private $contactModel;
public function __construct()
{
$this->contactModel = new contact();
}
public function index()
{
$number_of_rows = sizeof($this->contactModel->getAll());
$page_size = $this->contactModel->getPageSize();
$size_of_page = ceil($number_of_rows / $page_size);
$page = 1;
if (isset($_GET['page'])) {
if (!is_numeric($_GET['page']) || $_GET['page'] < 1 || $_GET['page'] > $size_of_page) {
view('error.http.404');
}
$page = $_GET['page'];
}
$contacts = $this->contactModel->getAll($page);
$data = [
'contacts' => $contacts,
'page' => $page,
'size_of_page' => $size_of_page
];
view('home.index', $data);
}
}