I want to change my URLs in a PHP application so that it uses friendly urls.
If i start it the url = localhost/Inhaalopdracht/MEOK1/MVCthuis/boeken/index.php?author=1
I want it to be something like: localhost/Inhaalopdracht/MEOK1/MVCthuis/boeken/index.php/author/1
This is my index:
<?php
//lees de controller
require_once("controller/Controller.php");
//start de controller
$controller = new Controller();
$controller->start();
?>
My controller:
<?php
require_once("model/Model.php");
class Controller
{
public $model;
public function __construct()
{
$this->model = new Model();
}
public function start()
{
if(!isset($_GET['book']) && !isset($_GET['author']))
{
$books = $this->model->getBookList();
include 'view/booklist.php';
}
else if(isset($_GET['book']))
{
$book = $this->model->getBook($_GET['book']);
include 'view/viewbook.php';
}
else if(isset($_GET['author']))
{
$author = $this->model->getAuthor($_GET['author']);
$books = $this->model->getBookList();
include 'view/viewauthor.php';
}
}
}
?>
And an example of one of the pages with info:
<html>
<head>
<title>De boekenlijst </title>
</head>
<body>
<table>
<tr>
<th> Titel </th>
<th> Schrijver </th>
<th> ISBN </th>
</tr>
<?php
foreach ($books as $key => $book)
{
echo '<tr>';
echo '<td><a href="index.php?book=' . $book->id . '">' . $book->title . '</a></td>';
echo '<td><a href="index.php?author=' . $book->id . '">' . $book->author . '</a></td>';
echo '<td>' . $book->isbn . '</td>';
echo '</tr>';
}
?>
</table>
</body>
</html>