Perancangan dan Pemrograman Web

Perancangan dan Pemrograman Web
Slide Note
Embed
Share

Bekerja dengan database menggunakan PHP, create, modify, and delete table menggunakan PHP - Framework untuk mengolah database. Tipe framework yang dominan: MVC.

  • PHP
  • MVC
  • Framework
  • Database
  • Web

Uploaded on Feb 24, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. 1 Perancangan dan Pemrograman Web Week 13 Model View Controller Oleh: Chaerul Anwar, MTI

  2. 2

  3. 3 Objective Bekerja dengan database menggunakan PHP Create, modify, and delete table menggunakan PHP - Framework Menggunakan PHP Framework untuk mengolah database

  4. Tipe framework yang dominan: MVC Framework yang berdasarkan MVC membagi komponen dalam 3 bagian Model, View, Controller Model DB HTML, CSS, Templates Controller Template

  5. PHP & MVC The model view controller pattern is the most used pattern for today s world web applications It has been used for the first time in Smalltalk and then adopted and popularized by Java At present there are more than a dozen PHP web frameworks based on MVC pattern

  6. PHP & MVC The model is responsible to manage the data The view (presentation) is responsible to display the data provided by the model in a specific format The controller handles the model and view layers to work together

  7. PHP & MVC

  8. PHP & MVC

  9. 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; } } ?>

  10. model/Model.php <?php include_once("model/Book.php"); class Model { public function getBookList() { // here goes some hardcoded values to simulate the database return array( "Jungle Book" => new Book("Jungle Book", "R. Kipling", "A classic book."), "Moonwalker" => new Book("Moonwalker", "J. Walker", ""), "PHP for Dummies" => new Book("PHP for Dummies", "Some Smart Guy", "") ); } public function getBook($title) { // we use the previous function to get all the books // and then we return the requested one. // in a real life scenario this will be done through // a database select command $allBooks = $this->getBookList(); return $allBooks[$title]; } } ?>

  11. 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>

  12. 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>

  13. controller/Controller.php <?php include_once("model/Model.php"); class Controller { public $model; public function __construct() { $this->model = new Model(); }

  14. controller/Controller.php public function invoke() { if (!isset($_GET['book'])) { // no special book is requested, we'll show a list of all available books $books = $this->model->getBookList(); include 'view/booklist.php'; } else { // show the requested book $book = $this->model->getBook($_GET['book']); include 'view/viewbook.php'; } } } ?>

  15. index.php <?php // All interaction goes through the index and is forwarded // directly to the controller include_once("controller/Controller.php"); $controller = new Controller(); $controller->invoke(); ?>

  16. PHP & MVC

  17. 17 Sekian - Terima Kasih

More Related Content