P EMROGRAMAN W EB II Lasmedi afuan, ST.,M.Cs
T OPIC CI URL Controller View
CI (C ODE I GNITER ) CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.
C ODE I GNITER URL URL pada CI didesain lebih user friendly “URLs in CodeIgniter are designed to be search- engine and human friendly” CI menggunakan pendekatan url berbasis segment example.com/ news / article /my_article class method Id atau variabel yang akan dilewatkan melalui controller
URL S UFFIX Menambahkan url suffix example.com/index.php/products/view/shoes Menjadi example.com/index.php/products/view/shoes.html File yang harus dimodifikasi config/config.php Dengan url suffix, dapat menambahkan ekstensi sesuai dengan keiinginan.
C ONTROLLER Controller di CI berfungsi sebagai intermediary yang menghubungkan antara model dengan view.
M Y F IRST C ONTROLLER <?php Class Blog extends CI_Controller { public function index() { echo “this is my first controller”; } ?>
CO NTROLLER Lokasi penyimpanan controller C:\xampp\CI_FOLDER\Application\controllers
N AMA KELAS Valid Tidak valid
E XTENDS Digunakan untuk melalukan inherit dari class CI_Controller
S ELALU INGAT INI
N EXT C ONTROLLER <?php Class Blog extends CI_Controller { public function index() { echo "this is my first controller"; } public function myprofil() { echo "this is my profile"; } ?>
M ENGAKSES HALAMAN MYPROFIL Localhost/CI213/index.php/Blog/myprofil
M ELEWATKAN VARIABEL UNTUK DITAMPILKAN MELALUI CONTROLLER <?php Class Blog extends CI_Controller { public funtion tampil($nim,$nama) { echo “$nim $nama”; } ?>
<?php Class Blog extends CI_Controller { public function index() { echo "this is my first controller"; } public function myprofil() { echo "this is my profile"; } public function tampil($nim,$nama) { echo “$nim $nama”; } ?>
C LASS CONSTRUCTOR Jika ingin menggunakan controller parent Parent::__construct();
R ESERVED N AMES Controller Name Controller CI_Base _ci_initialize Default index
R ESERVED N AMES Functions is_really_writable() load_class() get_config() config_item() show_error() show_404() log_message() _exception_handler() get_instance()
Variables $config $mimes $lang
V IEW Menampilkan halaman web ( webpage) ke user. (ci_view.php) Belajar CI CI ku yang pertama
L OADING V IEW Ingat !! Controller digunakan untuk menjembatani antara model dan view
L OADING V IEW $this->load->view(‘ view name ');
<?php Class Blogview extends CI_Controller { public function index() { $this->load->view(‘ci_view’); } ?>
L OADING MULTIPLE VIEW <?php Class Blogview extends CI_Controller { public function index() { $this->load->view(‘header’); $this->load->view(‘kiri’); $this->load->view(‘kanan’); $this->load->view(‘footer’); } ?>