Web Programming : Meet 4 (Konfigurasi CodeIgniter)

Meet 4 : Konfigurasi CodeIgniter / Download Framework CodeIgniter Disini

Pada folder Config

autoload.php

baris ke 61 – $autoload[‘libraries’] = array(‘database’);

baris ke 92 – $autoload[‘helper’] = array(‘url’);

config.php

baris ke 27 – $config[‘base_url’] = ‘http://localhost/wp2’;

database.php

baris ke 78 sampai 81 (disesuaikan dengan nama database)

‘hostname’ => ‘localhost’,
‘username’ => ‘root’,
‘password’ => ”,
‘database’ => ‘db_mhs’,
‘dbdriver’ => ‘mysqli’,

routes.php

baris ke 52 $route[‘default_controller’] = ‘mahasiswa’;

$route yang digunakan adalah controller mahasiswa.


Buat Sebuah Controller dengan nama Mahasiswa.php didalam folder Controller (application/controllers)

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

class Mahasiswa extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->model('Mhs_model');
    }

  public function index()
  {
    $data = array(
          'mhs' => $this->Mhs_model->data(),
        );

    $this->load->view('data_mhs',$data);	
  }

}

Buat view baru dengan nama data_mhs.php didalam folder Views (application/views)

<!doctype html>
<html>
  <head>
    <title>Data Mahasiswa</title>
  </head>
<body>
  <table width="100%" border="1">
    <tr>
      <td>No</td>
      <td>NIM</td>
      <td>Nama</td>
      <td>Jurusan</td>
    </tr>
    <tr>
      <td>1</td>
      <td>1234567</td>
      <td>Agnes W</td>
      <td>Informatics Computer</td>
    </tr>
    <tr>
      <td>2</td>
      <td>1234567</td>
      <td>Agus R</td>
      <td>Informatics Computer</td>
    </tr>
    <tr>
      <td>3</td>
      <td>1234567</td>
      <td>Ahmad Fauzi</td>
      <td>Informatics Computer</td>
    </tr>
    <tr>
      <td>4</td>
      <td>1234567</td>
      <td>Ahmad Krisdianto</td>
      <td>Informatics Computer</td>
    </tr>
    <tr>
      <td>5</td>
      <td>1234567</td>
      <td>Eni Maryanti</td>
      <td>Informatics Computer</td>
    </tr>
  </table>
</body>
</html>

Buat model baru dengan nama Mhs_model.php didalam folder models (application/models)

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

class Mhs_model extends CI_Model
{

    function __construct()
    {
        parent::__construct();
    }

    function data(){
        //return $this->db->query("SELECT * FROM data_mhs")->result();
        return $this->db->get('data_mhs')->result();
    }

}

 

Recommended For You

About the Author: adyrhs

Leave a Reply

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