0% found this document useful (0 votes)
9 views8 pages

OOPHP and MVC Basics in PHP

This document discusses object-oriented programming in PHP and the model-view-controller (MVC) framework. It explains that in OOPHP, classes like Book and BookController need to be created. For MVC, controllers manage models and views, with the BookController managing the Book model and list view. All model, view and controller code is typically placed in a single PHP file like BookController.php, which includes the model file and contains methods to support interaction between models and views. The index.php file routes user requests to controller methods and acts as the single point of entry. The number of controllers needed depends on the complexity of the web app.

Uploaded by

Ke Syukuran Ku
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

OOPHP and MVC Basics in PHP

This document discusses object-oriented programming in PHP and the model-view-controller (MVC) framework. It explains that in OOPHP, classes like Book and BookController need to be created. For MVC, controllers manage models and views, with the BookController managing the Book model and list view. All model, view and controller code is typically placed in a single PHP file like BookController.php, which includes the model file and contains methods to support interaction between models and views. The index.php file routes user requests to controller methods and acts as the single point of entry. The number of controllers needed depends on the complexity of the web app.

Uploaded by

Ke Syukuran Ku
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Week7Lab

OOPHP + MVC

OOPHP
When you adopt
object oriented
programming in
PHP, you need to
create PHP classes.
For example:
Book class
BookController class

<?php
Class Book {
private $conn;
public function __construct()
{
$conn = null;
}
// methods

?>

MVC
In MVC, Controllers manage the
Models and Views
For example in Read All Comments
Use Case, BookController manage
Book Model([Link])
List View ([Link])

MVC
Practically, to create MVC in PHP, all
Model, View and Controller need to
be placed in one PHP file.
In the Guestbook application, they
are all placed in
[Link]

[Link]
On top of the file, we can include
(require_once) the model file
([Link])
The middle part of the file consist of
methods or logics to support
interaction between model and view
E.g. view() function is to support
interaction between view_all() method
in [Link] and [Link]

[Link]
In the methods, you should decide
which View file that should be
included or displayed in the browser
like [Link], [Link] and so on.
You should remember that in MVC, all
files are separated according to their
role (model or view or controller)

Role of [Link]
The [Link] role is to divert user
requests to run methods in Controller
like:
[Link]?op=read view()
[Link]?op=delete remove()

[Link] becomes the single point


to refer

How many controllers does a single


web app need?
It really depends on the web app.
In Guestbook example, one is
probably sufficient.
If you were to implement a full blown
app like ecommerce app with
shipping, tax, inventory
management, tiered pricing, etc.,
then you just might want to have a
couple more.

You might also like