having fun with code igniter
TRANSCRIPT
Have fun with CodeIgniter Framework
23 April 2016
& Ahmad Arif
About Me Pendidikan
1998-2004 SDN 1 Kertamulya, Karawang 2004-2007 SMPN 2 Rengasdengklok, Karawang 2007-2010 SMAN 1 Rengasdengklok, Karawang 2010-2014 Informatika Universitas Jenderal Achman Yani 2015-???? Informatika Institut Teknologi Bandung
Minat Programming Machine Learning Artificial Intelligent
Game Technology
Entertainment Etc
What is framework? Framework = Kerangka kerja Menyediakan struktur umum aplikasi sehingga
memudahkan pengembang dalam menyimpan kode dalam aplikasi
Menangani tugas umum– Database– Business logic– Form handling
What is CodeIgniter? CodeIgniter framework aplikasi web ringan yang
ditulis dalam bahasa pemrograman PHP, dan mengadopsi pendekatan Model-View-Controller.
Kenapa menggunakan CodeIgniter?
Feature rich Lightweight/small Open source Well-supported by an active community Excellent “by example” documentation Easy to configure (nearly zero configuration) Supports multiple databases Cleaner code High Performance
https://github.com/kenjis/php-framework-benchmark
Model-View-Controller Model – merepresentasikan data View – menyajikan data untuk interaksi dengan
user Controller – mengontrol model dan data supaya
bisa saling berinteraksi
CodeIgniter Classes CI’s built-in classes berisi fungsi dasar yang
sering digunakan oleh aplikasi web Beberapa kelas yang sering digunakan:
– Database– Input– Loader– URI– Validation
Database Class Mengolah queri menggunakan the Active Record /
ORM Pattern Menyediakan metode “chaining” untuk
kemudahan query $this->db->where(‘name’,$name);
Input Class Menyediakan akses ke input pengguna dan data
lainnya:– Form fields (POST)– Cookies– Server variables
$this->input->post(‘fieldname’);
Loader Class Membuat berbagai resource:
– Databases– Views– Helpers– Plugins
$this->load->view(‘viewname’);
URI Class Menyediakan akses ke bagian-bagian tertentu
dari String URI Berguna untuk membangung RESTful API $this->uri->segment(n);
Other Classes Benchmarking Calendaring Email Encryption File uploading FTP HTML Table Image Manipulation
Language (internationalization) Output Pagination Session Trackback Unit testing XML-RPC Zip encoding
Helpers and Plugins CodeIgniter dilengkapi dengan berbagai “helper”
yaitu fungsi yang menambahkan kenyamanan terhadap aplikasi dan memberikan kemudahan reuse code.
$this->load->helper(‘helper_name’); CodeIgniter juga memungkinkan untuk
penggunaan kustom add-on yang disebut “plugins”.
$this->load->plugin(‘plugin_name’);
Getting Started Tools
– Apache HTTP Server– MySQL Database– PHP– Browser– Code Editor
XAMP, WAMP, MAMP, LAMPP
Notepad Notepad++ Sublime
Atom PHP Storm Etc
Getting Started To Do List
– Installation– Controller– View– Model– RESTful API
Controller<?php class BlogController extends CI_Controller {
public function index() { echo 'Hello World!';
}
public function comments() { echo 'Look at this!';
} }
<?php class BlogController extends CI_Controller {
…
public function page($index) { echo 'Page: !' . $index;
}}
View
<html><head>
<title>My Blog</title></head><body>
<h1>Welcome to my Blog!<h1></body></html>
index.php
$this->load->view(“index”);Add this code in controller
View<html><head>
<title>My Blog</title></head><body>
Welcome <strong><?php echo $name ?><strong></body></html>
index.php
$data = array(“name” => “Ahmad Arif”
);$this->load->view(“index”, $data);
Add this code in controller
Model Create database and table Setting database (config/database.php)
Modelclass Blog extends CI_Model {
$tableName = “blog”;
public function insert($title, $content){ $data = array(
“title” => $title,“content” => $content
);
$this->db->insert($this->tableName, $data);
}
}
Modelclass Blog extends CI_Model {
...
public function update($id, $title, $content){ $data = array(
“title” => $title,“content” => $content
);
$this->db->where(“id”, $id);$this->db->update($this->tableName,
$data);}
}
Model
class Blog extends CI_Model {
...
public function delete($id){ $this->db->where(“id”, $id);$this->db->delete($this->tableName);
}
}
Modelclass Blog extends CI_Model {
...
public function getAll(){ return $this->db->get($this->tableName)-
>result();}
public function getById($id){ $this->db->where(“id”, $id);return $this->db->get($this->tableName)-
>row();}
}
Using Model
class BlogController extends CI_Controller {
...
public function insert(){ $this->load->model(“Blog”);
$title = $this->input->post(“title”);$content = $this->input->post(“content”);
$this->Blog->insert($title, $content);}
}
RESTful API Tools
– Postman– Code Editor
To Do List– Format JSON/XML– Routing– Cache setting
References https://codeigniter.com https://google.com https://github.com/ahmadarif
Tank You