<html>
<head>
<meta charset ="UTF-8">
<title> index </title>
</head>
<body>
<?php
include_once("controller/Controller.php");
$controller =new Controller();
$controller ->invoke();
?>
</body>
</html>
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Controller > Controller.php
<?php
include_once("model/Model.php");
class Controller
{
public $model;
public function __construct()
{
$this->model = new Model();
}
public function invoke()
{
if(!isset($_GET['book']))
{
$books =$this->model->getBookList();
include 'View/booklist.php';
}
else
{
$book =$this->model->getBook($_GET['book']);
include 'View/viewbook.php';
}
}
}
?>
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
model > Book.php
<?php
class Book
{
public $title;
public $author;
public $description;
public function __construct($title,$author,$description)
{
$this->title =$title;
$this->author =$author;
$this->description = $description;
}
}
?>
################################################################################
Model > Model.php
<?php
include_once("model/Book.php");
class Model
{
public function getBookList()
{
return array(
"Jungle Book" => new Book("Jungle Book","R.kipling","A class book"),
"Moonwalker" => new Book ("Moonwalker","J.walker"," good"),
"PHP for Dummies" => new Book("PHP for Dummies","Some Smart gay"," nice")
);
}
public function getBook($title)
{
$allBooks =$this->getBookList();
return $allBooks[$title];
}
}
?>
###################################################################################
view > booklist.php
<html>
<head> </head>
<body>
<table>
<tbody>
<tr>
<td> Title </td>
<td> Author </td>
<td> Description </td>
</tr>
</tbody>
<?php
foreach ($books as $book)
{
echo '<tr><td> <a href="index.php?book=' .
$book->title . '">' . $book->title .'</a></td><td>' .
$book->author .'</td><td>' . $book->description .'</td></tr>';
}
?>
</table>
</body>
</html>
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
view > viewbook.php
<html>
<head> </head>
<body>
<?php
echo 'Title:' .$book->title .'<br/>';
echo 'Author:' .$book->author .'<br/>';
echo 'Description:' .$book->description .'<br/>';
?>
</body>
</html>
No comments:
Post a Comment