Khóa học thực hành thiết kế website với Wordpress (Dành cho người mới bắt đầu)
-
Saturday, September 2, 2017
2
Comments
//file book_model.php Class Book_Model {
Public $dataTemp = array(
1 => array(
“title” => “Yii framerk”,
“description” => “Yii framework description”,
“price” => 45.5
),
2 => array(
“title” => “javascript ahead”,
“description” => “javascript ahead description”,
“price” => 15.8
),
3 => array(
“title” => “PHP Beginner”,
“descrition” => “PHP Beginner description”,
“price” => 55.55
)
);
Public function getListBooks()
{
Return $this->dataTemp;
}
Public function getBook($id)
{
Return $this->dataTemp[$id];
}
}
//file book_controller.php
//Nội dung của trang controller.php
include “model/book_model.php”;
Class Book_Controller {
Public $model;
Public function __constructor()
{
$this->model = new Book_Model();
}
Public function invoke()
{
Switch($atc)
{
Case “view” :
$id = $_GET[“id”] || 0;
$this->view($id);break;
Case “list”:
Default:
$this->list();break;
}
}
Public function list()
{
$listBooks = $this->model->getListBooks();
include “view/booklist.php”;
}
Public function view($id)
{
$bookView = $this->model->getBook($id);
include “view/bookview.php”;
}
}
//file view/booklist.php
<html>
<head><title>Book List</title></head>
<body>
<table>
<tr>
<td>Title</td>
<td>Decscription</td>
<td>Price</td>
</tr>
<?php
foreach ($listBooks as $book)
{
echo '<tr>
<td>
<a href="index.php?book='.$book[“title”].'">' .$book[“title”]. '</a></td><td>' .$book[“description”].'</td><td>' .$book[“price”].'</td>
</tr>';
}
?> </table>
</body>
</html>
//file view/bookview.php
<html>
<head><title>Book View</title></head>
<body>
<h3><?= $bookView[“title”]; ?></h3>
<span class=”description”> <?= $bookView[“description”];?></span>
<span class=”price”><?= number_format($bookView[“price”];?></span>
</body>
</html>
<?php
$c = $_GET[“controller”] || “home”; $act = $_GET[“action”];
include “controller/$c_controller.php”; $c = $c.”_controller”; $controller = new $c; $controller->invoke();
?>