Framework: CodeIgniter

CodeIgniter adalah PHP frameworks. CodeIgniter diperkenalkan pada tahun 2006. CodeIgniter perlu di download di codeigniter.com. CodeIgniter menggunakan sistem MVC (Model-View-Controller). Di dalam sistem CodeIgniter terdapat tiga folder utama iaitu controllers, models dan views.

Code di folder controllers, Blog.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Blog extends CI_Controller {
 public function index()
 {
 echo "This statement from function index";
 }
 
 public function controllers($parameter1="", $parameter2="")
 {
 echo "This statement from function controller<br>";
 echo "The parameter: $parameter1 $parameter2";
 }
 
 public function views($name="")
 {
 $this->load->view('header');
 $data = array("name"=>$name);
 $this->load->view('blog_views',$data);
 }
 
 public function models()
 {
 echo "This statement from function model<br>";
 $this->load->model('profile');
 $data = $this->profile->getData();
 echo "Full Name:".$data["fullName"]."<br>";
 echo "Phone:".$data["phone"];
 }
}

Code di folder models, Profile.php

<?php

class Profile extends CI_Model { 
 public function getData()
 {
 return ['fullName'=>'Shahrul Nizam','phone'=>'0136289844'];
 } 
}

Code di folder views, header.php

<head>
<title>CodeIgniter Test</title>
</head>
<h1>This is the header</h1>

Code di folder views, blog_views.php

<html>
This statement from views<br>
The parameter: <?php echo $name; ?>
</html>

Contoh

  1. http://shahrulnizam.com/web/codeigniter/index.php/blog
  2. http://shahrulnizam.com/web/codeigniter/index.php/blog/controllers/Shahrul
  3. http://shahrulnizam.com/web/codeigniter/index.php/blog/views/Shahrul
  4. http://shahrulnizam.com/web/codeigniter/index.php/blog/models

Penerangan lanjut di

  1. http://tutorialcodeigniter.com/beginners/creating-controller.html
  2. http://tutorialcodeigniter.com/beginners/creating-view.html
  3. http://tutorialcodeigniter.com/beginners/creating-model.html

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.