27
Have fun with CodeIgniter Framework 23 April 2016 & Ahmad Arif

Having fun with code igniter

Embed Size (px)

Citation preview

Page 1: Having fun with code igniter

Have fun with CodeIgniter Framework

23 April 2016

& Ahmad Arif

Page 2: Having fun with code igniter

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

Page 3: Having fun with code igniter

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

Page 4: Having fun with code igniter

What is CodeIgniter? CodeIgniter framework aplikasi web ringan yang

ditulis dalam bahasa pemrograman PHP, dan mengadopsi pendekatan Model-View-Controller.

Page 5: Having fun with code igniter

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

Page 6: Having fun with code igniter

Model-View-Controller Model – merepresentasikan data View – menyajikan data untuk interaksi dengan

user Controller – mengontrol model dan data supaya

bisa saling berinteraksi

Page 7: Having fun with code igniter

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

Page 8: Having fun with code igniter

Database Class Mengolah queri menggunakan the Active Record /

ORM Pattern Menyediakan metode “chaining” untuk

kemudahan query $this->db->where(‘name’,$name);

Page 9: Having fun with code igniter

Input Class Menyediakan akses ke input pengguna dan data

lainnya:– Form fields (POST)– Cookies– Server variables

$this->input->post(‘fieldname’);

Page 10: Having fun with code igniter

Loader Class Membuat berbagai resource:

– Databases– Views– Helpers– Plugins

$this->load->view(‘viewname’);

Page 11: Having fun with code igniter

URI Class Menyediakan akses ke bagian-bagian tertentu

dari String URI Berguna untuk membangung RESTful API $this->uri->segment(n);

Page 12: Having fun with code igniter

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

Page 13: Having fun with code igniter

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’);

Page 14: Having fun with code igniter

Getting Started Tools

– Apache HTTP Server– MySQL Database– PHP– Browser– Code Editor

XAMP, WAMP, MAMP, LAMPP

Notepad Notepad++ Sublime

Atom PHP Storm Etc

Page 15: Having fun with code igniter

Getting Started To Do List

– Installation– Controller– View– Model– RESTful API

Page 16: Having fun with code igniter

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;

}}

Page 17: Having fun with code igniter

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

Page 18: Having fun with code igniter

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

Page 19: Having fun with code igniter

Model Create database and table Setting database (config/database.php)

Page 20: Having fun with code igniter

Modelclass Blog extends CI_Model {

$tableName = “blog”;

public function insert($title, $content){ $data = array(

“title” => $title,“content” => $content

);

$this->db->insert($this->tableName, $data);

}

}

Page 21: Having fun with code igniter

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);}

}

Page 22: Having fun with code igniter

Model

class Blog extends CI_Model {

...

public function delete($id){ $this->db->where(“id”, $id);$this->db->delete($this->tableName);

}

}

Page 23: Having fun with code igniter

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();}

}

Page 24: Having fun with code igniter

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);}

}

Page 25: Having fun with code igniter

RESTful API Tools

– Postman– Code Editor

To Do List– Format JSON/XML– Routing– Cache setting

Page 26: Having fun with code igniter

References https://codeigniter.com https://google.com https://github.com/ahmadarif

Page 27: Having fun with code igniter

Tank You