Konsep MVC

You might also like

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

Course

Chapter 1

by
Setiya Nugroho, S.T., M.Eng.

11 September 2023
Framework
• A framework is a program that is used to help developers
develop code consistently to develop web-based applications.
• With a framework, developers can reduce the number of bugs
on the websites or applications they create. Because, functions
and variables are already available in the framework
components.

12/09/23 2
Framework Functions
1) Speed up the application development process
• Framework provides a ready-to-use framework so developers don't have to create
everything from scratch. This allows to save time and effort in application
development.
2) Makes application maintenance and debugging easier
• In application maintenance, the framework provides various features that can
organize and simplify program code. This allows developers to easily update or
repair applications without having to change the entire structure or logic in
them. The framework also provides mechanisms that make the debugging
process easier. Developers can use features like logging, error handling.
3) Makes collaboration easier
• This is because frameworks provide a clear and structured framework for
carrying out the tasks that need to be completed.

12/09/23 3
Framework Functions
4) Reduce code length
• By using a framework, we no longer need to carry out a long coding process.
Each framework comes with a standard code template that we can use.
5) Improve database skills
• By using a framework, we can avoid repetition or duplication of code. This of
course can improve database capabilities.
6) Improve scalability
• This allows developers to add new features or adapt applications to support
larger data volumes without having to significantly change the architecture.
7) Strengthen security
• Frameworks generally have implemented standard security features, such as
safeguarding against SQL Injection attacks, Cross-Site Scripting (XSS).

12/09/23 4
Types of Frameworks for Web Development
• PHP Framework
• Laravel · CodeIgniter · Symfony · Zend · Phalcon · Yii · FuelPHP.

• JavaScript Framework
• Angular · React · Vue.js · Ember.js · Meteor · Mithril · Node.js · Polymer.

• CSS Frameworks
• Bootstrap · Tailwind CSS · Foundation · Bulma · Skeleton · Fomantic UI

• Python Frameworks : Django, Flask, Pyramid.


12/09/23 5
CodeIgniter
• CodeIgniter is a PHP framework developed by Rick Ellis of Ellis
Lab. CI is designed to be a web framework that is light and
easy to use.
• Confessions from Rasmus Lerdorf, the creator of the PHP
programming language, said that CodeIgniter is an easy and
reliable web framework.
• CodeIgniter makes it easier for developers to build dynamic
PHP applications because it is open source. CodeIgniter
provides a collection of libraries for frequently performed tasks
and is very easy to access.

12/09/23 6
CodeIgniter version
• Dukungan Versi PHP
• CodeIgniter versi 4 memerlukan versi minimum PHP yaitu versi 7.2,
sedangkan CodeIgniter versi 3 menggunakan PHP 5.6 (versi ini telah
dihentikan).
• Organisasi Direktori
• CodeIgniter versi 4 memiliki 5 direktori folder yaitu /app, /vendor, /public,
/writable, /test. CodeIgniter versi 3 memiliki 2 direktori folder yaitu
/application, /system.
• Penggunaan namespace
• CodeIgniter versi 4 menggunakan namespace. Sedangkan CodeIgniter versi 3
tidak menggunakan namespace.
• Autoloading
• CodeIgniter versi 4 memiliki proses autoloading yang lebih efisien dan
salah satu faktornya adalah penggunaan namespace 12/09/23 7
CodeIgniter version
• Penggunaan entitas
• CodeIgniter versi 4 memiliki dukungan untuk penggunaan entitas yang
membantu menyusun bagian database dari aplikasi mewakili kolom yang ada
di tabelnya.
• Dukungan file .env
• CI versi 4 memiliki dukungan untuk file .env yang memungkinkan
pengoptimalan pengaturan pada berbagai lingkungan kerja (produksi,
pengujian, pengembangan).
• Migrasi antar versi
• CodeIgniter versi 4 tidak kompatibel dengan versi sebelumnya. Migrasi dari
versi CodeIgniter 2.x ke versi CodeIgniter 3.x hanya dengan menimpa file
pada direktori dan memperbaharui nama file.
12/09/23 8
CodeIgniter version
• Command Line Interface
• CodeIgniter 4 saat ini sudah bertransformasi menjadi FrameWork PHP yang
modern dengan disertakannya fitur CLI.
• Instalasi Aplikasi
• Di versi 3, harus men-download file CodeIgniter nya terlebih dahulu. Di
versi 4, CI menggunakan Composer. Cukup 1 baris perintah CLI.
• Local Development Server
• menjalankan server website melalui terminal : php spark serve
• Fitur REST
• REST API ada di CodeIgniter 4
• Dokumentasi
• Dokumentasi di CodeIgniter 4 lebih lengkap, namun bersifat teknis.

12/09/23 9
Terms in CodeIgniter
• Model, a PHP class designed to work with information from a
database.
• Controller, the core of the application that determines the handling
of HTTP requests.
• View, web pages such as headers, footers, sidebars and others
embedded in web pages. View is never called directly. The view
must be called from the controller.
• Library, class that contains functions to solve certain cases.
• Helper, certain categories of task helpers consist of a collection of
functions.
• Driver, a special library that has a parent class and several derived
classes that can be used for certain cases.

12/09/23 10
MVC (Model View Controller)
• Mengontrol data.
Model • Pengambilan dan penyimpanan data sebuah dari database.

• Mengatur tampilan dengan format spesifik.


View

• Menghubungkan model dan view.


Controller • Tujuan utama user melakukan request.

12/09/23 11
MVC (Model View Controller)
tes
Controller Cha
nge
da not
Up ifica
tion
Ma
n ip
ulat
es
Templates
View Uses Model
Layout, etc.
See
s
Database
HTML, XML, Web Service
JSON, RSS, etc. etc.
.

12/09/23 12
How MVC Works in CodeIgniter
• index.php acts as the front-end controller, and initializes the
resources needed to run CodeIgniter
• The router examines the HTTP request to determine what to do
• If the cache file exists, it will be displayed directly, bypassing
normal system execution
• Before loading the controller, the HTTP request will check what the
user submitted and filter it for security
• Controller contains models, core libraries, plugins, helpers, and
other resources to process specific requests.
• View is displayed in the browser according to the process carried
out by the controller. If caching is running, the view will be cached
first so that it can be displayed in the next request.

12/09/23 13
CodeIgniter Directory Structure
• application folder : determining error pages, building controllers,
building models, building views, configuring web applications that
are built, building your own libraries, building your own helpers.
• system folder : stores the core CodeIgniter library in the core folder,
stores libraries and drivers for the database in the database folder,
stores fonts in the font folder, stores a collection of helpers in the
helpers folder, stores language features in the language folder,
stores various other libraries in the folder libraries.
• user_guide folder contains documentation files for introducing
CodeIgniter regarding: discussion of general features of
CodeIgniter, use of libraries, helpers and drivers found in
CodeIgniter.

12/09/23 14
Controller
• Controller adalah perantara Model, View, dan resource lainya yang
dibutuhkan untuk menangani HTTP request dan menghasilkan halaman
web.
• Sebuah controller pada hakekatnya merupakan sebuah Class. Sesuai
namanya “Controller”, bagian ini bertugas mengontrol seluruh aplikasi
menggunakan URI.
• URI (Uniform Resource Identifier) membantu dalam mengambil data
melalui URL CodeIgniter. Cara penyebutan URI segment pada
CodeIgniter misalnya segment 1, segment 2, segment 3 dan seterusnya.
• Segment 1 pada codeigniter adalah nama class atau controller yang
sedang dijalankan. Segment ke 2 adalah nama method atau function
pada class/controller. Segment 3 berupa data berbentuk id yang dikirim.

12/09/23 15
• Pada file controller Welcome didefinisikan sebuah class yang
bernama Welcome. Nama class itu juga sebaga nama
controllernya. Class Welcome memiliki method dg nama index.
• Berikut tampilan di browser yang mengakses controller Welcome :
• Nama dari sebuah Class Controller harus
diawali dengan huruf besar.
• Pada URI Class Controller harus
dipanggil menggunakan huruf kecil.
• Jangan menggunakan nama yang sama
antara nama Class dengan nama
Method, karena akan mengakibatkan
fungsi Parent Class di overwrite.
12/09/23 16
12/09/23 17
12/09/23 18
Thank you

12/09/23 19

You might also like