PHP Framework Design With Hierarchical M PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

PHP FRAMEWORK DESIGN WITH HIERARCHICAL MODEL-VIEW-

CONTROLLER ARCHITECTURE
Ahmad1, Zainal Arifin2, Dyna Marisa Khairina3
Computer Science Department, Mathematics and Natural Science Faculty Mulawarman University Samarinda 1,2,3
rawndummy@gmail.com1, zainal_arifin@fmipa.unmul.ac.id2, dyna.ilkom@gmail.com3

Abstract
The development of internet today makes website as the most popular information system media. Among several
programming languages that can be used to build a website, PHP is the open source web-programming language and
very popular among any programmers. Web building method from time to time also has its progress. From the
beginning using the conventional method raises some obstacles, until finally evolved to the use of the framework that
has many advantages in terms of management and library files. The framework has been widely spread on the internet
that can be used to create a website, especially for users of PHP today. Among the many frameworks, architectures
used affect the effectiveness of the use of the framework. The purpose of this research is to design a PHP framework
that implements the architecture of the Hierarchical Model-View-Controller (HMVC) system which was originally
developed for desktop applications. HMVC is an architecture that consists of a layer of MVC (Model-View-Controller)
that has a derivative relationship hierarchically. The final results is the form of a PHP application framework with
HMVC architecture which results in a system that can help make large-scale websites and worked as a team.
Keywords: PHP, Framework, Website, Hierarchical Model-View-Controller (HMVC).

1 INTRODUCTION Model-View-Controller). HMVC split into sections per


The web is currently used for a wide range of module. Each module has its own MVC layer, so that
purposes, including to search for information, business, when imported moved enough alone. Not only that,
social media, etc. The fact that it can be accessed HMVC then allows a module has a derivative like
through various devices make use of the web is so hierarchy. HMVC first applied to desktop applications.
popular. Surely this could not be separated from the From there, the author decided to apply the HMVC to
innovation made by web developers. Then the web web framework.
attracting some circles to be involved in the world of
web. 2 STRUCTURE OF WRITING
Web consists of a set of documents that are 2.1 Problem Formulation
connected to form pages. Web can be run as part of Based on the background, then formulated a
server software. Server software is software that is problem, including:
placed on the server to process requests from clients. 1. How does the process work a PHP framework that
There are some server software that can be used in uses HMVC architecture?
making the web, one of which is PHP. PHP is a server 2. How is the implementation of the architecture
software that is open-source and has a lot of developers. HMVC PHP framework on a simple website
Speaking of making web certainly not out of the creation?
manufacturing techniques. Web which consists of a set 3. How to make a PHP framework that is in
of files must use good programming techniques for accordance with the PSR-0 standard, PSR-1 and
management to be easy to deploy. In the beginning the PSR-2?
web was made not so regular, yet require the use of the
framework. Making the web tend to use the same code 2.2 Boundary Problem
over and over again, then this is where web developers To avoid the spread of the issues discussed, the
to develop the framework. Framework to package a researchers limited the problem:
number of codes that can be used repeatedly (reusable) 1. PHP framework that will be built is more devoted to
for all web creation is done. the development of the website version 2.0.
Making the web then developed using the MVC 2. PHP framework that will be built this using OOP
architecture (Model-View-Controller). MVC separates (Object-Oriented Programming) with server PHP
the code into three parts, namely the process version 5.3 or latest version.
(controller), part of the data (model) and the display 3. the format used by the PHP framework is the path
(view). Then allows the use of MVC web workmanship format.
be divided. Team members who are more likely to be 4. Database library to be used by this PHP framework
able to focus on doing the code logic section and team is the libraries for MySQL version 5 or latest using
members were more likely to be the focus of the design MySQLi extension (MySQL Improved).
work on the display. 5. Users PHP framework that will be built this is a
MVC architecture still has some constraints. When PHP programmer with intermediate skill level up.
some web code will be imported into other web, the 6. Part libraries that will be described on the PHP
MVC should be moved to three different locations. framework is a model, view, controller, route, and
MVC then developed into a more modular. database.
Development of MVC called with HMVC (Hierarchical
2.3 Research Goals code from scratch [1]. Web Application Framework
This research was conducted to develop a PHP ideal for building web-based applications because it is
framework that uses HMVC architecture, so as to create more flexible, secure and use a more structured pattern.
a PHP framework has advantages, including: Examples of Web Application Framework such as
1. Suitable for large-scale website development and Zend, CakePHP, Kohana, Laravel, CodeIgniter,
worked as a team. Symfony Project Yii, Prado, and others.
2. Provides optimum libraries are loaded to assist in In the creation of websites, especially those done in
the development of web applications. teams, will be hard to steer thinking if team members
3. It has manual (user guide) for developers to help in do not use the framework. Development of the
learning the use of this PHP framework. framework is done with the aim of providing a space
4. Have tools such as a generator to create models and for the programmer to not split up of the rules that have
modules. been agreed. A framework must have a standard that
5. Characteristically open source, can be developed by has been set maker. People who use the framework can
anyone for free. still be creative as you wish while still adhering to the
standards set in the framework that is used. Therefore,
2.4 Benefits of Research the Indonesian framework known as the frame work.
The benefits to be gained from this research are:
1. Knowing more profound engineering process that 3.3 HMVC (Hierarchical Model-View-Controller)
uses a PHP framework HMVC architecture and Architecture
design pattern Singleton Pattern. HMVC (Hierarchical Model-View-Controller)
2. Find out more specifically how a PHP framework Architecture consists of a layer of MVC (Model-View-
can work based programming rules that have been Controller) which can have a hierarchical relationship
set in it. derivative [3]. In the article, discusses JavaWorld
3. Can be used as a basis for further development of HMVC design for desktop applications, especially
the system is more advanced PHP framework. those using the Java programming language. However,
4. Stimulate interest to web developers use PHP in this study will be discussed on how to implement
framework to build a website, either for secondary HMVC PHP framework architecture in website
level and for the beginner level. creation. HMVC is an MVC pattern but a hierarchy in
5. Provide knowledge for website developers who use which the MVC implementation stored in specific
PHP framework without knowing the inner modules so that each module of the model, view, and
workings of PHP frameworks it uses. controller itself [5].
HMVC architecture provide clear boundaries for
3 METHODOLOGY each layer. Limiting layer is referred to as a module
3.1 PHP (PHP: Hypertext Preprocessor) (module). Because HMVC is a development of the
PHP stands for "PHP: Hypertext Preprocessor", MVC architecture, the term MVC will continue to be
which is a scripting language that is attached to the used in its application. Each module has the MVC
HyperText Markup Language (HTML). Most of the which stands independently. A module will not
language syntax is similar to C, Java and Perl, PHP plus interfere with other modules. By doing so, the module
some specific functions. The main purpose of this is said to have clear boundaries. HMVC architecture
language is to allow web developers to write dynamic can be seen in figure 1.
web pages quickly [6].
PHP was created by Rasmus Lerdorf in 1995. At
that time PHP was named FI (Form Interpreted), which
is realized in the form of a set of scripts that are used to
process data from the web form. Furthermore Rasmus
released the source code to the public and named PHP /
FI. With the release of the source code to be open
source, there are many programmers who are interested
in developing PHP. Now the new version of PHP was
developed by Zend, Zend Framework developers.

3.2 Web Application Framework


Web application framework is a software
framework that designed to support developing of
dynamic web, web application and web service.
Framework is a set of statements or basic functions that
form certainly rules and interact with each other so that
in making the application site must follow the rules of
the framework [7]. Framework can be defined as a set
of or a collection of pieces arranged or organized
program such that it can be used to help make the
whole web application without having to make all the
Figure 1 HMVC Architecture
When compared to the MVC architecture, HMVC There are three sub-sections inside, namely
architecture has several advantages [4], namely: Model, View, and Controller.
1. Modularity: HMVC makes it easier to interchange d. Model is a sub-part of a module that serves as the
chunks of code through encapsulation of data collection.
functionality. e. View is a sub-part of a module whose job is to
2. Organization: HMVC allows each module to display the output of a piece of HTML code that
contain its own models, views, and controllers will form the web content.
f. Controller is a sub-part of a module that serves as
directories, keeping related files contained.
the main controller module, and bridges the
3. Extensibility: By promoting modularity, HMVC
relationship between the model and the view.
allows systems to be more easily extended by g. Plugin is a kind of module, so that there are the
simply adding or replacing modules. separate parts of MVC. The plugin is used to form
4. Reusability: Since modules can call each other, a module with features from third-party providers.
HMVC allows for code to be easily reused. h. Component is part of the application that allows
users to create their own libraries (user-defined)
3.4 Flowchart for use by the application.
Flowchart can be used to show the sequence of i. Asset is part of an application that aims to
events from a computer-based information systems. accommodate and provide access to client-script
This flow chart shows the sequence of processes in the application or media needed by web.
system by exposing the media input, output, and other j. Theme is part of the application that provides the
types of storage media in the data processing [2]. main view to a web page.
Layout is a sub-part of a theme that will be the
4 RESULTS AND DISCUSSIONS content module (container) to form a complete web
4.1 System Section page.
The system in question here is a PHP framework.
PHP framework consists of several parts that work 4.3 Workflow of System
together to run the application. The system is built Workflow is a system design that describes how
using the PHP file containing the class definition. There the flow from the beginning to the end of a working
are some classes that are made in the system, but the system in general. The subject that will be discussed
part is not shared by the class system. Part of the only the workflow system, not including workflow
system is divided by function. applications.
a. Boot Loader is part of a system that aims to
initialize and load the rest of the system required
by the application.
b. Routing is part of a system which aims to perform
the addressing.
c. System Controller is part of the system which is
the control center module that performs the
execution of the application.
d. System View is part of a system that serves to
process the input from the System Controller into
HTML documents with the help of the DOM
(Document Object Model) HTML.
e. System Model is part of a system that handles the
use of a model made by the application.
f. Database Driver is part of a system that aims to Figure 2 Workflow of Djokka Framework
open up access to the database is done by the
System Model.
g. Helpers are part of the system that served to Figure 2 Shows the workflow of Djokka
provide assistance in the development of web Framework when running a web system that is being
applications. executed. When a user accesses a web application, then
the first run is the index.php file located in the root web
4.2 Application Section application. In this file, the boot loader is called to load
Application in question here is a website built by the Djokka Framework system. Once invoked, the boot
users. Such a system, the application is also divided
loader will be run.
into several sections. This division will help the system
to execute a web application. Boot loader is part of a PHP framework that runs
the boot process. The boot process includes loading of
a. Bootstrap is a part of the application that is
all configurations contained in the web application.
executed when the web first started. This section
Configuration forms data used to adjust some parts of
will call and run the Boot Loader section of the
the system that can be set. There are several pre-
system to execute the application.
b. Configuration is part of the application that is used defined configurations on Djokka Framework, one
to hold settings or the web configuration. example is the database configuration.
c. Module is part of the application that will be Once the configuration is loaded, process is continued
executed by the system to generate web content. to the routing part. In this section the system will
determine which module to be executed within a web Mulai

application. The determination is done by processing Membaca URI

the URI (Uniform Resource Location). After


determining which module is to be executed, the
Module = “index”
Action = “index”
Dir = ModuleDir()

process continues to the system controller.


System controller is the control center of the
True False
False
URI mengandung
URI kosong?
simbol slash?

process. System controller will execute the modules Routes = Explode(‘/’, URI)
Jml_Rute = Count(Rute)
True Module = URI

that have been determined by the routing part. The Tmp_Mod = null
Prev_Mod = null
Params = Array()
Module = “index”

function performed by this section depends on the i=0


Path = Dir + URI + “/”

process contained in the executable module. Within a i < Jml_Rute


False
Params = ArraySlice(Routes, i + 1)

module are the model, view and controller. The module True Last_Part = UcFirst(LastPart(‘/’, Module);

must have a controller, but it does not necessarily have Module = Routes[i]
Tmp_Mod += Routes[i] + “/”
True
i=0
Route = Module + “/” + Action
Function = “action” + UcFirst(Action)
Class = “Djokka\Controllers\” + Last_Part

to have a view and a model.


False
Module_Dir = Path
Path = Path + “/” + Last_Part + “.php”
Tmp_Mod += “modules/” + Routes[i] + “/”

System controller then becomes the central control Action = Routes[i]


Path = Dir + Prev_Mod

system. Some of the supporting web applications, such


Path = Dir + Tmp_Mod

as: components, plugins, modules, and helpers, will Berkas Path


ditemukan?
False
Selesai

play if in the controller module is written orders calling True


True

to that support part. Thus, the system controller only Prev_Mod += Routes[i] + “/” i=0
False

runs part of the supporting required course. If there is Module += “/” + Routes[i]
Prev_Mod += “modules/” + Routes[i] + “/”

no supporting parts is needed, then the process will


continue to the next stage.
i++

If the module executed has model calling process, Figure 3 Flowchart Forming HMVC Architecture
then the part that handles it is system model. In web
application, model can be used for validation or 4.4 Rule of System
accessing database. If a model is used for validation, As framework, there is a rule used to give scope to
then system can run supporting part namely Validation. user in order not to split or out of rule. Those rules
If model needs database connection, then system model include as system design. Rules that have been decided
with the database driver help will open database to be followed in framework are:
connection and give the access. Data from database will a. Rule of module manufacture
be fed back to database driver then to system model and b. Rule of sub-module manufacture
get fed back again to system controller. From system c. Rule of controller module manufacture
controller then data will be continued to model d. Rule of action function manufacture
accessed by module controller. e. Rule of view manufacture
Output resulted from system controller is an web f. Rule of model manufacture
content information and the list of web asset needed by
a module. Web asset is client-script file, like JavaScript 4.5 System Interface Implementation
file and CSS. That information will be continued to Error handler is error message that will be
system view for further processed. With the DOM displayed by system when it is found error experienced
HTML help, system view will run rendering, so that it when web project execution. Error message displayed
results HTML document output. DOM standing for is designed in such a way in order that web programmer
Document Object Model is library that is actually can repair error experienced. Term of this error
available in any web browser. But now it is also correction is called debugging. Figure 4 shows error
available in PHP. Output resulted from rendering message display along trace faults.
process is HTML document that will be received by
web browser to be displayed next.
Part of system applying HMVC architecture is
called HMVC engine, it is an engine used to collect the
information of a module according to HMVC
architecture. That information can be used by system
determining module location that will be executed.
Figure 3, shows flowchart forming HMVC architecture

Figure 4 Error Message Display along trace faults


Sometimes a web programmer who first uses a
PHP framework must know the structure of the laying
of the file. In order to facilitate the programmer to
know the directory structure of the files laying, then
made a tool that is embedded in the system Djokka
Framework. This tool is named "Project Builder", is
used to display the directory structure that will be used
by the web project. Display Project Builder tool is
shown in Figure 5.

Figure 7 Views Creator Tools Active Record

4.6 System Testing


Testing for the system is done by implementing the
use of Djokka Framework in making a website. The
making of this website will test the success of Djokka
Framework in making website. The website that will be
built is a website that can be used for news publishing.
Website can be managed by an administrator and web
Figure 5 Views Tooling Project Builder visitor can give feedback comment to news.

Tools with the name "Creator Module" is provided


for novice web programmers who will use Djokka
Framework, not knowing how to manufacture the
module, and just want to feel the ease in making
modules. This tool can create a module in accordance
with the rule-making module in Djokka Framework.
Display Module Creator tool can be seen in Figure 6.

Figure 8 Display Home Page

Figure 9 Admin Pages Display

Figure 8 and Figure 9 show the results of websites


that are built using Djokka Framework. As Figure 8
Figure 6 Display of Module Creator tool shows the view of the Home page, while Figure 9
shows the view from the Admin.
Active Record is a model that features connectivity The test also includes performance measurement
to the database. A tool called "Active Record Creator" benchmarking. Benchmarking is done by using the
has been implanted in the Djokka Framework, serves to parameter number of requests per second that can be
make the model as an abstraction to a table in the done as a benchmark. Two well-known PHP
database that is used. Display Active Record Creator frameworks will be compared with the PHP framework.
tool can be seen in Figure 7. Benchmarking is accomplished using the default
console of PHP, which is ApacheBench. Computer /
laptop that is used in this process specification:

a. OS Windows 7 Home Premium 64 bit


b. Intel(R) processor Core i7 2.00 GHz
c. 8 GB RAM 4. The PHP framework complies with the PSR (PHP
d. Web Server Apache version 2.4.7 Standard Recommended), more specifically: PSR-
e. PHP version 5.5.6 0, PSR-1 and PSR-2.
5. Systems can be used in the manufacture of large-
Benchmarking is done by testing Djokka scale web sites which need collaboration of many
Framework PHP framework along with two other well- people.
known people, including: Yii Framework and 6. Based on the test results were compared to three
CodeIgniter. Each of the PHP framework created a web frameworks, resulting that the Requests per
test which only displays the message "Hello World". Second (RPS) for Djokka Framework is higher.
By using the Command Prompt, each measured
performance PHP framework by typing the command 6 REFERENCES
"ab-n 50 URLs". The intention is to send the command [1] Basuki, A.P. "Membangun Web Berbasis PHP
as many as 50 requests on the URL address of the web dengan Framework Codeigniter". Lokomedia,
experiments each tested PHP framework. Once the Yogyakarta, 2010
request is done, then the Command Prompt will appear [2] Bin Ladjamudin, Al-Bahra. "Analisis dan Desain
benchmarking results. The ratio of the number of Sistem Informasi". Graha Ilmu, Yogyakarta, 2005
requests made per second is displayed in graphical form [3] Cai, Jason., Kapila, Ranjit. dan Pal, Gaurav.
in Figure 10. "HMVC: The layered pattern for developing
strong client tiers.",
<http://www.javaworld.com/jw-07-2000/jw-0721-
hmvc.html> accessed on 16 May 2013
[4] Crow, Wesley. "Hierarchical Model-View-
Controller (HMVC): Planning For The Future",
<http://somethingstatic.com/hierarchical-model-
view-controller-planning-future> accessed on 16
May 2013
[5] Hidayat, Eka Wahyu. "Penerapan Pola
Hierarchical Model-View-Controller Pada
Rekayasa Sistem Berbasis Web Framework".
Jurnal Teknologi TechnoScientia, Indonesia,
Figure 10 Comparison Chart Value RPS (Request Volume 3: 2, 2011, ISSN: 1979-8415
per Second) PHP Framework is tested [6] Nugroho, Bunafit. "Latihan Membuat Aplikasi
Web PHP dan MySQL dengan Dreamweaver MX
5 CONCLUSIONS (6, 7, 2004) dan 8". Gava Media, Yogyakarta,
From the research that has been done, it can be 2008
concluded: [7] Wardana,. "Menjadi Master PHP dengan
1. PHP framework architecture using Hierarchical Framework Codeigniter", PT.Elex Media
Model-View-Controller is generated. Komputindo, Jakarta, 2010
2. The PHP framework can avoid collisions between
class attributes and class attributes artificial library
users.
3. The PHP framework can provide a broader space
for the formation of the pages in the website
creation and storage capacity is not too large.

You might also like