Code Igniter

Embed Size (px)

DESCRIPTION

materi kuliah CodeIgniter dari UGM

Citation preview

  • CodeIgniter

    CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications

    Shofiq Sulaiman [[email protected]]

  • HTML

    .CSS.input{width:140px;.Javascript

    function () {PHP

  • PerawatanPembaharuan

    Tetapi, adakah keunggulannya ?

  • Adalah sekumpulan fungsi, class, dan aturan-aturan.Berbeda dengan library yang sifatnya untuk tujuan tertentu saja, framework bersifat menyeluruh mengatur bagaimana kita membangun aplikasi.Lebih Cepat, Lebih Baik. Developer akan lebih fokus pada pokok permasalahan (masalah koneksi database, form validation, GUI, security, dsb telah disediakan oleh framework atau library).Teknologi tinggi berbiaya rendahAlih-alih membangun semuanya sendirian, lebih baik menggunakan resource yang sudah ada dan teruji (Ancaman Sang Naga, Ming Zeng, hal 55)

  • ModelConnects business objects and database tables to create a persistable domain model where logic and data are presented in one wrapping.

    View Helper classes to display html elements in your views.

    Controller Is made up of one or more actions that performs its purpose and then either renders a template or redirects to another action. An action is defined as a public method in the controller, which will automatically be made accessible to the web-server through a mod_rewrite mapping.

  • The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.The View is the information that is being presented to a user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of "page".The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.

  • KeuntunganStruktur yang konsisten. Sangat berguna bila developer banyak dan turnover tinggi.Struktur merupakan best practices. Semua sudah ditempatkan di tempat yang paling sesuai.Dapat belajar tentang desain aplikasi yang baik. Hanya library dan helper yang dibutuhkan yang diload.Dokumentasi yang lengkap

    KerugianButuh investasi waktu belajar dan adaptasi

  • Web Server & DatabaseApache, PHP, MySQL, WAMP, LAMP, AppServ, dsbEditor CodePSPad, Dreamweaver, Notepad++, dsbBrowserIE, Firefox Mozila, Chrome, Opera, Safari, dsbCodeIgniter CodeIgniter_1.7.0.zipJika belum ada sebagian atau seluruhnya belumada, anda dapat ambil di \\sulaiman\windows\Ekstrak CodeIgniter_1.7.0.zip dan langsung jalan

  • The index.php serves as the front controller, initializing the base resources needed to run CodeIgniter.The Router examines the HTTP request to determine what should be done with it.If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.Security. Before the application controller is loaded, the HTTP request and any user submitted data is filtered for security.The Controller loads the model, core libraries, plugins, helpers, and any other resources needed to process the specific request.The finalized View is rendered then sent to the web browser to be seen. If caching is enabled, the view is cached first so that on subsequent requests it can be served.

  • A Controller is simply a class file that is named in a way that can be associated with a URI.The second segment of the URI determines which function in the controller gets called.If your URI contains more then two segments they will be passed to your function as parameters.A view is simply a web page, or a page fragment, like a header, footer, sidebar, etc.To load a particular view file you will use the following function:$this->load->view('name, $data);Models are PHP classes that are designed to work with information in your database.To load a model you will use the following function:$this->load->model('Model_name');

  • helper file is simply a collection of functions in a particular category, performs one specific task, with no dependence on other functionsLoading a helper file is quite simple using the following function:$this->load->helper('name');Auto-loading Helpers in application/config/autoload.php fileOnce you've loaded the Helper File containing the function you intend to use, you'll call it the way you would a standard PHP function.Plugins work almost identically to Helpers plugin usually provides a single function, whereas a Helper is usually a collection of functionsLoading a plugin file is quite simple using the following function:$this->load->plugin('name');Auto-loading Plugins in application/config/autoload.php fileMenggunakan fungsi dalam library :$this->someclass->some_function(); // Object instances will always be lower case

  • XSS Filtering$config['global_xss_filtering'] = TRUE;

    Active Record$query = $this->db->get('mytable'); // Produces: SELECT * FROM mytable

    Parser {judul} $this->parser->parse(judul', CodeIgniter);

  • Fungsi

    function SetTanggal($tanggal) { $bln=array('Januari','Februari','Maret','April','Mei','Juni','Juli ,'Agustus, 'September','Oktober','November','Desember'); $tlen = sizeof($bln); $tgl=explode('-',$tanggal); for ($t=0;$t

  • Classclass Waktu { function Waktu() { } function SetWaktu($waktu) { $wakt = explode(" ",$waktu); $tanggal = $wakt[0]; return $tanggal.' '.$wakt[1]; }}Pemakaian

    $waktuObj = new Waktu();$waktu = $waktuObj->SetWaktu(2009-05-03 12:13:20);

  • CREATE DATABASE `mitm`;

    USE `mitm`;

    CREATE TABLE `buku_tamu` ( `BukuTamuId` int(10) NOT NULL auto_increment, `BukuTamuNama` char(30) default NULL, `BukuTamuEmail` char(50) default NULL, `BukuTamuIsi` char(255) default NULL, `BukuTamuWaktu` datetime default NULL, PRIMARY KEY (`BukuTamuId`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

    insert into `buku_tamu`(`BukuTamuId`,`BukuTamuNama`,`BukuTamuEmail`,`BukuTamuIsi`,`BukuTamuWaktu`) values (1,'Sulaiman','[email protected]','Yang pertama nie','2009-05-23 13:21:52');

  • Telah diberikan contoh untuk menampilkan data buku tamu dari database di atas

    Dengan code di atas kita dapat melihat daftar buku tamu sekaligus menambahkannnya

    Silahkan anda lengkapi untuk aksi edit dan delete data

    Setelah itu tambahkan paging

  • Banyak hal dalam CodeIgniter yang belum tersampaikan

    Mohon maaf dan terima kasih