CodeIgniter Template Integration (CTI)

Case study:

1. Look for free website themes, as an example reference you can use the following link:

2. Integrate the theme with the latest version of the CodeIgniter framework.

3. Display all data in the northwind table on the themes you downloaded.

4. At meeting 10, collect 1 sheet of screenshots of the themes you downloaded, the URL download link for the themes, provide your student ID number and name to ensure that your themes are unique (not duplicated) with your friends.

Ulasan ini merupakan hasil pekerjaan tugas di kampus, dan sudah lolos pengajuan nilai dengan skor 100% poin penuh. Itu artinya, saya tidak perlu ragu-ragu lagi untuk membagikan tutorial ini kepada teman-teman semuanya.

SARAN:
1. Jangan lupa Aktifkan Speakernya
2. Jangan sampai kelewatan setiap detiknya, atau Anda hanya akan disibukan oleh error code yang tak kunjung usai.
3. Jangan lupa berdoa sebelum memulainya.

GOAL HARAPAN:
1. Saya harap Anda tidak hanya mendapatkan codenya tapi juga memahaminya,
2. Saya harap Anda tidak stuck saat interview dengan Dosen Pengapu,
3. Saya harap Anda bisa melanjutkannya meskipun saya menggunakan 2 contoh dalam tutorial ini.

CHECK POINT
Saya membuat beberapa rangkuman langkah / tahapan dalam mengerjakan tugas integrasi template ke codeigniter, kemudaian menampilkan tabel-tabel database northwind, diantaranya sebagai berikut:

1. Download Template
2. Download CodeIgniter last version
3. Kombinasikan komponen template dengan CodeIgniter
4. Konfigurasi CodeIgniter
5. Membuat halaman template sebagai halaman default / home --> (Goal: Template terintegrasi)
6. Menampilkan tabel-tabel database northwind --> (Goal: Menu Navigasi, Tabel2 Northwind tampil, Terintegrasi dengan Template)

Code sumber beserta penjelasannya secara lengkap bisa Anda simak di sini

### Tapi ini baru akan saya rilis pada tanggal 6/1/2017 pukul 22.00 PM,
karena saya tidak ingin menghambat kreativitas Anda ###

http://www.gatewan.com/cara-integrasi-template-codeigniter-menampilkan-tabel-database-northwind

    ===========================================
        -{             SELAMAT BELAJAR!!             }-   
          ===========================================
       _ +-------------------------------------------+ _
      /o)|             www.gatewan.com               |(o\
     / / | Gerbang Observasi Teknologi Algoritma dan | \ \
    ( (_ |  _             Pemrograman             _  | _) )
   ((\ \)+-/o)-----------------------------------(o\-+(/ /))
   (\\\ \_/ /                                     \ \_/ ///)
    \      /                  __                   \      /
     \____/                  |  |                   \____/
              +++++++++++++++++++++++++++++++++++++
             +               **                    +
             +   Don't miss out! Follow Us at:     +
             +                                     +
             + >> www.facebook.com/gatewan         +
             + >> www.twitter.com/gatewan          +
             +               **                    +
             ++++++++++++++++++++++++++++++++++++++
                             |  |
                             |  |
                            /|  |\
                    Admin by Wawan Beneran

Model Concept in MVC CodeIgniter

Models are documentation related to databases, such as DDL and DML.

NB: Before continuing reading, it is a good idea to understand this material beforehand  "Getting to Know the MVC Web Framework"

1. CodeIgniter User Guide Explains

Models are PHP classes designed to work with information in your database. For example, let's say you are using CodeIgniter to manage a blog. You might have a model class that contains functions for inserting, updating and retrieving blog data. Here's what a model class looks like:

<?php

class Blog_model extends CI_Model {

        public $title;
        public $content;
        public $date;

        public function __construct()
        {
                // Call the CI_Model constructor
                parent::__construct();
        }

        public function get_last_ten_entries()
        {
                $query = $this->db->get('entries', 10);
                return $query->result();
        }

        public function insert_entry()
        {
                $this->title    = $_POST['title']; // please read the below note
                $this->content  = $_POST['content'];
                $this->date     = time();

                $this->db->insert('entries', $this);
        }

        public function update_entry()
        {
                $this->title    = $_POST['title'];
                $this->content  = $_POST['content'];
                $this->date     = time();

                $this->db->update('entries', $this, array('id' => $_POST['id']));
        }

}

?>

2. Anatomy of the Model

Models and their classes are stored in the CodeIgniter >> application/models/ directory. They can also be grouped into subdirectories, if you want to organize them in a special way.

Basic prototype for model class:

<?php

class Model_name extends CI_Model {

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

}

?>

Where Model_name is the name of your class. The name must start with a capital letter and match the file name. Read the full rules  HERE .

Setup Steps

  • Database initialization
  • Connection Settings
  • Creating a Model Class.

a. Database Initialization

There are 2 ways to initialize a database:

1. Automatic way in  application/config/autoload.php folder . Modify autoload.php file on line 61.

<?php

/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in system/libraries/ or your
| application/libraries/ directory, with the addition of the
| 'database' library, which is somewhat of a special case.
|
| Prototype:
|
| $autoload['libraries'] = array('database', 'email', 'session');
|
| You can also supply an alternative library name to be assigned
| in the controller:
|
| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array('database'); //array default masih kosong -> isi dengan 'database'

?>

2. Manual method by calling the database load on each class that requires it.

$this->load->database();

b. Connection Settings

Connection settings are in application/config/database.php

In this case, I assume that you have imported the northwind database first.

<?php

$db['default'] = array(
 'dsn' => '',
 'hostname' => 'localhost',
 'username' => 'root',
 'password' => '',
 'database' => 'northwind',
...

?>

c. Creating a Class Model

In this case, the case study given to us is how to display Employees and Shippers data.

Displaying Employees Data

Please create a php file and its class with the name Employee_model and place it in the CodeIgniter application/models/ folder.

<?php
class Employee_model extends CI_Model{

 public function get_employee(){
  return $this->db->get("employees"); //cara 1

  /*
  Ada 2 cara untuk manajemen database class:
   cara 1, sebagaimana diatas.
   cara 2, menjalankan query secara lengkap --> $this->db->query('SELECT * FROM employees');

  Apabila ada klausa tambahan :
   cara 1, masih tetap --> $this->db->get('categories');
   cara 2, $this->db->like(' CategoryName',' Beverages');
  */

 }

}

?>

Please create a php file and its class named Employees and place it in the CodeIgniter application/controllers/ folder.

<?php
class Employees extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Employee_model'); //cara 1.

  /*
  Ada 2 cara untuk memanggil model:
   cara 1, diload disetiap class yang membutuhkannya. sebagaimana diatas.
   cara 2, diload secara otomatis di application\config\autoload.php :
   Pada line 135, Anda bisa menambahkan semacam ini:

   $autoload['model'] = array('Employee_model');
   jika sudah disebutkan disini, maka tidak perlu disebutkan lagi disetiap construct.

   Tambahan:
   $autoload['model'] = array('Employee_model'=>'em');
   'Employee_model'=>'em' -> 'em' digunakan untuk menyingkat pemangilan model di class lain
  */

 }

 public function index(){
  echo "<h1>Data Employees</h1>";
  $query = $this->Employee_model->get_employee();
  foreach($query->result() as $row):
   echo $row->EmployeeID.'. '.$row->FirstName ." ".$row->LastName;
   echo "<br />";
  endforeach;

 }

}

?>

Then display it by accessing the required Segment URI, please adjust it to each localhost. For me like this:

http://localhost/CodeIgniter-3.1.0/index.php/Employees

Tampilan Employees Database Northwind

Display Shippers Data

Please create a php file and its class with the name Shippers_model and place it in the CodeIgniter application/models/ folder.

<?php
class Shippers_model extends CI_Model{

 public function get_shippers(){
  return $this->db->get("shippers");

 }

}

?>

Please create a php file and its class with the name Shippers and place it in the CodeIgniter application/controllers/ folder.

<?php
class Shippers extends CI_Controller{

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

 public function index(){
  echo "<h1>Data Employees</h1>";
  $query = $this->Shippers_model->get_shippers();
  foreach($query->result() as $row):
   echo $row-> ShipperID.'. '.$row->CompanyName ." ".$row->Phone;
   echo "<br />";
  endforeach;

 }

}

?>

Show. Now URI Segment is changed to Shippers:

http://localhost/CodeIgniter-3.1.0/index.php/Shippers

Tampilan Shippers Database Northwind

Done. Happy learning!

Reference

  • User Guide CodeIgniter
  • Concept Model Module By Wahyu Widodo (Wahyusoft GitHub)

Controller Concept in CodeIgniter MVC

Controller is a framework documentation related to data requests, access directions, and connections. Controller connects users with the system and provides relevant inputs and outputs to users.

NB: Before continuing reading, it is a good idea to understand this material beforehand  "Getting to Know the MVC Web Framework"

1. CodeIgniter User Guide Explains

All requests must go through index.php, which is defined with BASEPATH. This is useful to prevent direct access to models, libraries, or anything else related to security.

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

Information:

  • The defined() function is a function definition to check whether a constant exists.
  • BASEPATH is one of the  constant names that CodeIgniter  defines.
  • exit() is a function to print a string and end script execution.

2. Create a Controller

Please create a php file named "Pertama" then save it to the CodeIgniter Controller directory. Here is the content of the Pertama.php file:

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

class Pertama extends CI_Controller{

 public function index()
 {
  echo "Bersama GATEWAN Belajar CodeIgniter Sampai Mahir";
 }
}

3. How to access the Controller?

As explained previously, we must go through index.php first, then access the URL for my local PC like this, please adjust it to your respective local PC.

http://localhost/CodeIgniter-3.1.0/index.php/pertama

First Controller View.php

4. What is meant by URI & segment?

URI stands for Uniform Resource Identifier, allowing us to retrieve data through CodeIgniter URL. CodeIgniter URI Segment is after index.php and consists of several segments such as:

  • Segment 1 = controller file name or class name
  • Segment 2 = name of method or function in the class/controller
  • Segment 3 = can be an id or parameter.

Examples of Segment URIs:

http://localhost/CodeIgniter-3.1.0/index.php/segment1/segment2/segment3

or

http://localhost/CodeIgniter-3.1.0/index.php/controller/method/id

In order to clarify the picture of URI Segment, let's continue by adding several methods to the Pertama.php controller.

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

class Pertama extends CI_Controller{

 public function index()
 {
  echo "Bersama GATEWAN Belajar CodeIgniter Sampai Mahir";
 }

 public function kedua($nama,$usia)
 {
 echo "Nama saya {$nama} usia {$usia} <br />";
 }

}

5. How to access URI Segment?

You can directly enter the $name and $age variables into the segment in the address bar, please fill them in with your respective names and ages, for example:

http://localhost/CodeIgniter-3.1.0/index.php/First/Second/Wawan/21

Example of URI Segment Display

Information:

  • In red circle = Link
  • First = File Controller
  • Second = Function / Method
  • Wawan, 21 = Function Parameters
  • First, Second, Wawan, 21 = Segments

6. How to Identify CodeIgniter Segments

Please modify the controller file Pertama.php, so that it looks like this:

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

class Pertama extends CI_Controller{

 public function index()
 {
  echo "Bersama GATEWAN Belajar CodeIgniter Sampai Mahir";
 }

 public function kedua($nama,$usia)
 {
  "Nama saya {$nama} usia {$usia} <br />";

  //Identifikasi Segement CodeIgniter
  $uri = '<ol>';
  $uri.= '<li>'.$this->uri->segment(1).'</li>';
  $uri.= '<li>'.$this->uri->segment(2).'</li>';
  $uri.= '<li>'.$this->uri->segment(3).'</li>';
  $uri.= '<li>'.$this->uri->segment(4).'</li>';
  $uri.= '</ol>';
  echo $uri;
 }

}

By utilizing CodeIgniter's segment() function, we can know which is the 1st, 2nd, 3rd segment and so on.

CodeIgniter Segment Identification

7. Class Constructors

1. Create a file named My_string_helper.php and save it in the helper folder:

<?php
/*
*bundet.com
*Wawan Beneran
*Library function tambahan yang sering digunakan (Create Helper)
*/

 function duit($data)
 {
  return 'Rp.' .number_format($data,0,",",".").',-';
 }

 function TglIndo($tanggal)
 {
  list($thn,$bln,$tgl)=explode('-',$tanggal);
  $tmp = $tgl."-".$bln."-".$thn;
  return $tmp;
 }

?>

2. Modify the controller file to access the helper you created:

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
*bundet.com
*Wawan Beneran
*Mengenal konsep Controller untuk mengakses Helper
*/
class Pertama extends CI_Controller{
public $gapok;
public $tunjangan;

 public function index()
 {
  echo "Bersama GATEWAN Belajar CodeIgniter Sampai Mahir";
 }

 public function kedua($nama,$usia)
 {
  "Nama saya {$nama} usia {$usia} <br />";

  //Identifikasi Segement CodeIgniter
  $uri = '<ol>';
  $uri.= '<li>'.$this->uri->segment(1).'</li>';
  $uri.= '<li>'.$this->uri->segment(2).'</li>';
  $uri.= '<li>'.$this->uri->segment(3).'</li>';
  $uri.= '<li>'.$this->uri->segment(4).'</li>';
  $uri.= '</ol>';
  echo $uri;
 }

 //2. Tambahkan function constructor dan panggil helper yang anda buat!
 public function __cunstruct()
 {
  parent::__construct();
  $this->load->helper("My_string_helper");
 }

 //3. Untuk mengetahui kegunaannya, tambahkan 2 method dibawah ini :
 private function _gaji($jmlbulan)
 {
  return ($this->gapok=1000000 + $this->tunjangan=500000) * $jmlbulan;
 }

 public function tampilgaji($jmlbulan)
 {
  $this->load->helper("My_string_helper");
  echo "Gaji selama {$jmlbulan} bulan : ".duit($this->_gaji($jmlbulan))."<br />";
  echo "Telah dibayar pada tanggal : ".TglIndo(date('Y-m-d'));
 }

}

?>

3. Run the controller file Pertama.php followed by the class tampilgaji. As you access the Segment URI.

a. Trial for 10 months.

http://localhost/CodeIgniter-3.1.0/index.php/pertama/tampilgaji/10

Display with 2nd segment 10 (for 10 months)

b. Trial for 30 months.

http://localhost/CodeIgniter-3.1.0/index.php/pertama/tampilgaji/30

Display with 2nd segment 30 (for 30 months)

Reference

View Concept in MVC CodeIgniter

View is documentation related to the appearance of the page, such as CSS, HTML, PHP.

NB: Before continuing reading, it is a good idea to understand this material beforehand  "Getting to Know the MVC Web Framework"

CodeIgniter User Guide Explains

View is a segment that regulates the appearance of a website page or fragment page, such as header, footer, sidebar, etc. Starting from the simplest view, to the most flexible view that is embedded in the CodeIgniter framework in particular. If you want a type of hierarchy, you can also do so by creating a new directory in the View directory.

Subject:

  1. HTML Handling
  2. Table Handling
  3. Form Handling
  4. URL Handling
  5. Training

What is the Use of View?

Segment specialist to organize the application display. In general there are two design categories that facilitate view segments, namely:

  • Helper
  • Library

The way to activate it is by loading the helper and library, for example:

$this->load->helper("html");
$this->load->library("table");

Or put it in the autoload.php configuration, so we don't need to put it again in the class that needs it, for example:

$autoload['libraries'] = array("table");
$autoload['helper'] = array("html","form","url");

1. HTML Handling

br()

This function is useful for forming html line tags, or for moving lines. Example:

echo br(3);

Then the HTML code will be formed:

</br></br></br>

heading()

This function is useful for forming html header tags (< h1 >, < h2 >, < h3 >). Example:

echo heading("Selamat Datang", 3);

Then the HTML code will be formed:

<h3>Selamat Datang</h3>

img()

This function is useful for forming html image tags (< img >). Example:

<?php

$image_properties = array(
"src" => "images/logo.jpg",
"alt" => "Ini adalah logo perusahaan",
"width" => "100", "height" => "100"
);

echo img($image_properties);

?>

Then the HTML code will be formed:

<img src="images/logo.jpg" alt="Ini adalah logo perusahaan" width="100" height="100">

link_tag()

This function is useful for forming html link tags (< link />). Example:

<?php

$link = array(
"href" => "css/printer.css",
"rel" => "stylesheet",
"type" => "text/css"
);

echo link_tag($link);

?>

Then the HTML code will be formed:

<link href="css/printer.css" rel="stylesheet" type="text/css">

nbs()

This function is useful for forming html "non-breaking spaces" tags ( ). Example:

echo nbs(3);

Then the HTML code will be formed:

&nbsp;&nbsp;&nbsp;

2. Table Handling

The table class provides functions that allow you to automatically create HTML tables from an array or a database result set. For example:

a. Directly Using Arrays

<?php

$data = array (
array("NIM","Nama"),
array("07018111", "Bayu"),
array("07018123", "Dewi"),
);

echo $this->table->generate($data);

?>

Then it will give a display like the following, still plain because without CSS touch. You only need to pay attention to the part indicated by the arrow.

To make it more attractive and look like a table, then what we need to do is to pack it with a template that has been provided by CodeIgniter. For example, consider the following code changes:

<?php

/* NOTE!
Penambahan code template harus diletakan atau dipanggil di atas blok code tabel
*/

//code template
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

//code tabel
$data = array (
array("NIM","Nama"),
array("07018111", "Bayu"),
array("07018123", "Dewi"),
);
echo $this->table->generate($data);

?>

Here are the changes:

b. Using set_heading and add_row

<?php

/* NOTE!
Penambahan code template harus diletakan atau dipanggil di atas blok code tabel
*/

//code template
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

//code tabel 2. Menggunakan set_heading dan add_row
$this->table->set_heading("NIM", "Nama");
$this->table->add_row("07018111", "Bayu");
$this->table->add_row("07018222", "Dewi");
$this->table->add_row("07018333", "Andi");
echo $this->table->generate();

?>

Then it will display:

c. Using a Single Database Result Set

At this point, I assume that you have imported the northwind database. and setup it in the CodeIgniter database configuration. ( \CodeIgniter\application\config\database.php ). Example:

<?php

/* NOTE!
Configurasi Database di CodeIgniter
*/

$db['default'] = array(
 'dsn' => '',
 'hostname' => 'localhost',
 'username' => 'root',
 'password' => '',
 'database' => 'northwind',
 'dbdriver' => 'mysqli',
 'dbprefix' => '',
 'pconnect' => FALSE,
 'db_debug' => (ENVIRONMENT !== 'production'),
 'cache_on' => FALSE,
 'cachedir' => '',
 'char_set' => 'utf8',
 'dbcollat' => 'utf8_general_ci',
 'swap_pre' => '',
 'encrypt' => FALSE,
 'compress' => FALSE,
 'stricton' => FALSE,
 'failover' => array(),
 'save_queries' => TRUE
);

?>

Next, you just need to modify the previous file in the View folder to:

<?php

/* NOTE!
Penambahan code template harus diletakan atau dipanggil di atas blok code tabel
*/

//code template
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

//code tabel 3. Menggunakan Satu Set Hasil Database
$query = $this->db->query('SELECT * FROM shippers'); //saya coba tampilkan tabel shippers

echo $this->table->generate($query);

?>

Here's what it looks like:

3. Form Handling

CodeIgniter also provides several form functions, which can help you in creating forms, including:

form_open()

Useful for creating form opening tags ( < form > ). Example:

echo form_open("mahasiswa/simpan?);

Then the HTML code will be formed:

<form method="post" action="http://localhost/index.php/mahasiswa/simpan">

form_hidden()

Useful for making hidden input field tags ( < input type="hidden"> ). Example:

echo form_hidden("username","wawan");

Then the HTML code will be formed:

<input type="hidden" name="username" value="wawan">

form_input()

Useful for creating non-hidden input field tags ( < input > ). Example:

echo form_input("nim","12131294");

Then the HTML code will be formed:

<input type="text" name="nim" value="12131294">

form_password()

Useful for creating password input tags ( < input type="password"> ). Example:

echo form_password("user_pass");

Then the HTML code will be formed:

<input type="password" name="user_pass" value="">

form_upload()

Useful for creating input tags for file uploads ( < input type="file"> ). Example:

$data = array (
"name" => "foto",
"size" => "30",
"style" => "width:50%"
);
echo form_upload($data);

Then the HTML code will be formed:

<input type="file" name="foto" size="30" style ="width:50%">

form_textarea()

Useful for creating textarea tags ( < textarea > ). Example:

$data = array (
"name"=> "alamat",
"rows" => "3"
"cols" => "10"
);

echo form_textarea($data);

Then the HTML code will be formed:

<textarea name="alamat" rows="3" cols ="10"></textarea>

form_dropdown()

Useful for creating selection tags ( < select > ) for dropdown menus (combo boxes). Example:

$option= array (
"satu" => "Kelompok 1",
"dua" => "Kelompok 2"
);

echo form_dropdown("kelompok", $option, "dua");

Then the HTML code will be formed:

<select name="kelompok">
<option value="satu">Kelompok 1</option>
<option value="dua" selected="selected">Kelompok 2</option>
</select>

form_submit()

Useful for creating submit buttons. Example:

echo form_submit("mysubmit", "Kirim");

Then the HTML code will be formed:

<input type="submit" name="mysubmit" value="Kirim">

form_close()

Useful for creating form closing tags ( < / form > ). Example:

echo form_close();

Then the HTML code will be formed:

</form>

4. URL Handling

CodeIgniter also provides the anchor() function to generate anchor tags ( < a > ). For example:

echo anchor("dosen/hapus/3","Klik Disini");

Then the HTML code will be formed:

<a href="http://localhost/index.php/dosen/hapus/3">Klik Disini</a>

5. Training

In this session, we are asked to display Employee data from the northwind database. So what we need to do is continue  the PREVIOUS MATERIAL .

a. Create a Controller File

Save the php file with the name Employees,

<?php
class Employees extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Employee_model','EM'); //cara 1.

  /*
  Ada 2 cara untuk memanggil model:
   cara 1, diload disetiap class yang membutuhkannya. sebagaimana diatas.
   cara 2, diload secara otomatis di application\config\autoload.php :
   Pada line 135, Anda bisa menambahkan semacam ini:

   $autoload['model'] = array('Employee_model');
   jika sudah disebutkan disini, maka tidak perlu disebutkan lagi disetiap construct.

   Tambahan:
   $autoload['model'] = array('Employee_model'=>'em');
   'Employee_model'=>'em' -> 'em' digunakan untuk menyingkat pemangilan model di class lain
  */

 }

 public function index(){
  /*echo "<h1>Data Employees</h1>";
  $query = $this->Employee_model->get_employee();
  foreach($query->result() as $row):
   echo $row->EmployeeID.'. '.$row->FirstName ." ".$row->LastName;
   echo "<br />";
  endforeach;
  */
  $data["title"] = "<h1>Data Employees</h1>";
  $data["array_emp"] = $this->EM->get_employee();
  $this->load->view('View_employees',$data);
 }

}

?>

b. Creating Model Files

Save the php file with the name Employee_model,

<?php
class Employee_model extends CI_Model{

 public function get_employee(){
  return $this->db->get("employees"); //cara 1

  /*
  Ada 2 cara untuk manajemen database class:
   cara 1, sebagaimana diatas.
   cara 2, menjalankan query secara lengkap --> $this->db->query('SELECT * FROM employees');

  Apabila ada klausa tambahan :
   cara 1, masih tetap --> $this->db->get('categories');
   cara 2, $this->db->like(' CategoryName',' Beverages');
  */

 }

}

?>

c. Create File View

Save the php file with the name View_employees,

<?php
echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'No.',
'Full Name',
'Birth Date');

  foreach($array_emp->result() as $row):
  $this->table->add_row(
   $row->EmployeeID,
   $row->FirstName ." ".$row->LastName,
   $row->BirthDate
   );
  endforeach;
  echo $this->table->generate();

?>

d. Show

Display employee data with a table

Not stopping there, we were also given a challenge before going home to display category data along with the amount of stock.

a. Create a Controller File

Save the php file with the name Categories,

<?php
class Categories extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Categories_model','EM'); //cara 1.

  /*
  Ada 2 cara untuk memanggil model:
   cara 1, diload disetiap class yang membutuhkannya. sebagaimana diatas.
   cara 2, diload secara otomatis di application\config\autoload.php :
   Pada line 135, Anda bisa menambahkan semacam ini:

   $autoload['model'] = array('Employee_model');
   jika sudah disebutkan disini, maka tidak perlu disebutkan lagi disetiap construct.

   Tambahan:
   $autoload['model'] = array('Employee_model'=>'em');
   'Employee_model'=>'em' -> 'em' digunakan untuk menyingkat pemangilan model di class lain
  */

 }

 public function index(){
  /*echo "<h1>Data Employees</h1>";
  $query = $this->Employee_model->get_employee();
  foreach($query->result() as $row):
   echo $row->EmployeeID.'. '.$row->FirstName ." ".$row->LastName;
   echo "<br />";
  endforeach;
  */
  $data["title"] = "<h1>Data Categories</h1>";
  $data["array_emp"] = $this->EM->data_categories();
  $this->load->view('View_categories',$data);
 }

}

?>

b. Creating Model Files

Save the php file with the name Categories_model,

<?php
class Categories_model extends CI_Model{

 public function data_categories(){
  $sql = "SELECT
    c.CategoryID,
    c.CategoryName,
    COUNT(*) AS jumlah
    FROM
  categories AS c JOIN products AS p
  ON c.CategoryID=p.categoryID
  GROUP BY c.categoryID";
  return $this->db->query($sql);
 }

}

?>

c. Create File View

Save the php file with the name View_categories,

<?php
echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'No.',
'Category Name',
'Jumlah Product');

  foreach($array_emp->result() as $row):
  $this->table->add_row(
   $row->CategoryID,
   $row->CategoryName,
   $row->jumlah
   );
  endforeach;
  echo $this->table->generate();

?>

d. Show

Displaying categories data with a table

Reference

  • User Guide CodeIgniter
  • Advanced Dynamic Web Application Module - Concept_View - By Wahyu Widodo (Github:Wahyousoft).

Solution

I provide 2 learning methods, namely in the form of special video tutorials for those of you who are visual learners, and also complete writing for those of you who are text learners (like to read).

https://youtu.be/m9ZuJf6f8R4

1. Download Template

Based on some of these referral links, I am interested in the template provided by  THIS site .

2. Download CodeIgniter Last Version

The last version I downloaded at that time was version 3.1.2, if until now there have been several updates, then you can use the latest version. Please download it  HERE .

3. Combine Template with CodeIgniter

First extract CodeIgniter to your local server root folder, coincidentally at that time I was using wampserver, so I extracted the file to the wampserver → www folder.

After that, rename the CodeIgniter folder to "TASK2" (to make it shorter). Next, create a new folder named "assets" in the root folder of TUGAS2, the use of this folder is to store customization files from the template that we have downloaded, such as files *css, *js, *font, dll.

Next, extract the template file and move the customization files to the CodeIgniter assets folder.

It so happens that the template I downloaded already has assets and images folders, so all I need to do is copy-paste the two folders into the TUGAS2 root folder.


Template Components

Here are the changes:


TASK2 component (CodeIgniter root)

4. Setting CodeIgniter Configuration

The next step is to set up the CodeIgniter configuration, we can start from:

4.1 .htaccess settings

The discussion about .htaccess will be reviewed specifically on the next occasion. For this topic, just change your .htaccess file to be like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

4.2 Routes settings

Buka file application → config → routes

Change the default_controller from 'welcome' to 'template'. The template name refers to the name of the controller file that we will use in this practicum.

<?php
...
$route['default_controller'] = 'template';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

4.3 Database setup

Buka file application → config → database

Since we are using northwind database, so please change the settings to be like this:

<?php
...
$active_group = 'default';
$query_builder = TRUE;

$db['default'] = array(
 'dsn' => '',
 'hostname' => 'localhost',
 'username' => 'root',
 'password' => '',
 'database' => 'northwind',
 'dbdriver' => 'mysqli',
 'dbprefix' => '',

4.4 Config settings

Buka file application → config → config

Change base_url to:

<?php
...
$config['base_url'] = 'http://localhost/TUGAS2';

4.5 Autoload settings

Buka file application → config → autoload

Because we will display the northwind database records in the form of a table, we need to use some of CodeIgniter's built-in libraries such as; table and database.

Not only that, we also need to use some of CodeIgniter's built-in helpers such as; html, form, and url.

The method we use is to call it automatically via autoload, please set it like this:

Baris 61 - libraries

<?php
...
$autoload['libraries'] = array('table','database');

Baris 92 - helper

<?php
...
$autoload['helper'] = array('html','form','url');

5. Template Integration

At this stage we just have to play with the MVC concept, if you don't understand it yet, please understand it first by following these practical instructions:

5.1 Create a Template File as Home

Add a Controller file by duplicating the Welcome.php file and renaming it to "Template.php", then adjust the class naming and its function.

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

class Template extends CI_Controller { //<-- sesuaikan nama classnya

 public function index()
 {
  $this->load->view('My_template'); //<-- atur juga file view yang perlu dipanggil
 }
}

Since the template file has no connection to the database, we don't need to create the Model, so we can continue to create the View.

In this case, I will break the downloaded template into several parts, namely:

  • Header.php
  • Main.php
  • Default_main.php

In View, add a folder named "Home", then add the three files above.

Now we need to go back to the folder where we extracted the downloaded template. There the file we need is index.html, please open it with your respective text editor.

Notice! The template split into 3 parts has gone through a previous review process by inspecting elements etc. (you can see more details in the video tutorial).

Copy-paste this section into Header.php

<!DOCTYPE HTML>
<!--
 Strata by HTML5 UP
 html5up.net | @ajlkn
 Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
 <head>
  <title>TUGAS 2 WDL</title> <!-- Title dirubah sesuai dengan studi kasus ->
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
  <link rel="stylesheet" href="assets/css/main.css" />
  <!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
 </head>
 <body id="top">

  <!-- Header -->
   <header id="header">
    <div class="inner">
     <a href="#" class="image avatar"><img src="images/avatar.jpg" alt="" /></a>

     <!--PENAMBAHAN MENU SIDEBAR / HEADER DISESUAIKAN BERDASARKAN STUDI KASUS-->
     <ul>
      <a href="<?php echo base_url()?>"><li>Beranda</li></a>
      <a href="<?php echo base_url()?>Categories"><li>Categories</li></a>
      <a href="<?php echo base_url()?>Customers"><li>Customers</li></a>
      <a href="<?php echo base_url()?>Employees"><li>Employees</li></a>
      <a href="<?php echo base_url()?>Orders"><li>Orders</li></a>
      <a href="<?php echo base_url()?>Products"><li>Products</li></a>
      <a href="<?php echo base_url()?>Shippers"><li>Shippers</li></a>
      <a href="<?php echo base_url()?>Suppliers"><li>Suppliers</li></a>
     </ul>
     <!--END MENU-->

     <!-- <h1><strong>I am Strata</strong>, a super simple<br />
     responsive site template freebie<br />
     crafted by <a href="http://html5up.net">HTML5 UP</a>.</h1>-->
    </div>
   </header>

  <!-- Main -->
   <div id="main">

    <!-- One -->
     <section id="one">

Copy-paste this section into Main.php

</section>
<!--
Ada beberapa elemen di sini yang kami hapus, dimaksudkan agar tidak mengganggu tampilan konten
tabel-tabel database northwind,
-->
   </div>

  <!-- Footer -->
   <footer id="footer">
    <div class="inner">
     <ul class="icons">
      <li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
      <li><a href="#" class="icon fa-github"><span class="label">Github</span></a></li>
      <li><a href="#" class="icon fa-dribbble"><span class="label">Dribbble</span></a></li>
      <li><a href="#" class="icon fa-envelope-o"><span class="label">Email</span></a></li>
     </ul>
     <ul class="copyright">
      <li>&copy; Wawan Beneran 12131294</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
     </ul>
    </div>
   </footer>

  <!-- Scripts -->
   <script src="assets/js/jquery.min.js"></script>
   <script src="assets/js/jquery.poptrox.min.js"></script>
   <script src="assets/js/skel.min.js"></script>
   <script src="assets/js/util.js"></script>
   <!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
   <script src="assets/js/main.js"></script>

 </body>
</html>

Copy-paste this section into Default_main.php

<header class="major">
       <h2>Ipsum lorem dolor aliquam ante commodo<br />
       magna sed accumsan arcu neque.</h2>
      </header>
      <p>Accumsan orci faucibus id eu lorem semper. Eu ac iaculis ac nunc nisi lorem vulputate lorem neque cubilia ac in adipiscing in curae lobortis tortor primis integer massa adipiscing id nisi accumsan pellentesque commodo blandit enim arcu non at amet id arcu magna. Accumsan orci faucibus id eu lorem semper nunc nisi lorem vulputate lorem neque cubilia.</p>
      <ul class="actions">
       <li><a href="#" class="button">Learn More</a></li>
      </ul>
     </section>

    <!-- Two -->
     <section id="two">
      <h2>Recent Work</h2>
      <div class="row">
       <article class="6u 12u$(xsmall) work-item">
        <a href="images/fulls/01.jpg" class="image fit thumb"><img src="images/thumbs/01.jpg" alt="" /></a>
        <h3>Magna sed consequat tempus</h3>
        <p>Lorem ipsum dolor sit amet nisl sed nullam feugiat.</p>
       </article>
       <article class="6u$ 12u$(xsmall) work-item">
        <a href="images/fulls/02.jpg" class="image fit thumb"><img src="images/thumbs/02.jpg" alt="" /></a>
        <h3>Ultricies lacinia interdum</h3>
        <p>Lorem ipsum dolor sit amet nisl sed nullam feugiat.</p>
       </article>
       <article class="6u 12u$(xsmall) work-item">
        <a href="images/fulls/03.jpg" class="image fit thumb"><img src="images/thumbs/03.jpg" alt="" /></a>
        <h3>Tortor metus commodo</h3>
        <p>Lorem ipsum dolor sit amet nisl sed nullam feugiat.</p>
       </article>
       <article class="6u$ 12u$(xsmall) work-item">
        <a href="images/fulls/04.jpg" class="image fit thumb"><img src="images/thumbs/04.jpg" alt="" /></a>
        <h3>Quam neque phasellus</h3>
        <p>Lorem ipsum dolor sit amet nisl sed nullam feugiat.</p>
       </article>
       <article class="6u 12u$(xsmall) work-item">
        <a href="images/fulls/05.jpg" class="image fit thumb"><img src="images/thumbs/05.jpg" alt="" /></a>
        <h3>Nunc enim commodo aliquet</h3>
        <p>Lorem ipsum dolor sit amet nisl sed nullam feugiat.</p>
       </article>
       <article class="6u$ 12u$(xsmall) work-item">
        <a href="images/fulls/06.jpg" class="image fit thumb"><img src="images/thumbs/06.jpg" alt="" /></a>
        <h3>Risus ornare lacinia</h3>
        <p>Lorem ipsum dolor sit amet nisl sed nullam feugiat.</p>
       </article>
      </div>
      <ul class="actions">
       <li><a href="#" class="button">Full Portfolio</a></li>
      </ul>
     </section>

    <!-- Three -->
     <section id="three">
      <h2>Get In Touch</h2>
      <p>Accumsan pellentesque commodo blandit enim arcu non at amet id arcu magna. Accumsan orci faucibus id eu lorem semper nunc nisi lorem vulputate lorem neque lorem ipsum dolor.</p>
      <div class="row">
       <div class="8u 12u$(small)">
        <form method="post" action="#">
         <div class="row uniform 50%">
          <div class="6u 12u$(xsmall)"><input type="text" name="name" id="name" placeholder="Name" /></div>
          <div class="6u$ 12u$(xsmall)"><input type="email" name="email" id="email" placeholder="Email" /></div>
          <div class="12u$"><textarea name="message" id="message" placeholder="Message" rows="4"></textarea></div>
         </div>
        </form>
        <ul class="actions">
         <li><input type="submit" value="Send Message" /></li>
        </ul>
       </div>
       <div class="4u$ 12u$(small)">
        <ul class="labeled-icons">
         <li>
          <h3 class="icon fa-home"><span class="label">Address</span></h3>
          1234 Somewhere Rd.<br />
          Nashville, TN 00000<br />
          United States
         </li>
         <li>
          <h3 class="icon fa-mobile"><span class="label">Phone</span></h3>
          000-000-0000
         </li>
         <li>
          <h3 class="icon fa-envelope-o"><span class="label">Email</span></h3>
          <a href="#">hello@untitled.tld</a>
         </li>
        </ul>
       </div>
      </div>
     </section>

    <!-- Four -->

   </div>

  <!-- Footer -->
   <footer id="footer">
    <div class="inner">
     <ul class="icons">
      <li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
      <li><a href="#" class="icon fa-github"><span class="label">Github</span></a></li>
      <li><a href="#" class="icon fa-dribbble"><span class="label">Dribbble</span></a></li>
      <li><a href="#" class="icon fa-envelope-o"><span class="label">Email</span></a></li>
     </ul>
     <ul class="copyright">
      <li>&copy; Wawan 12131294</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
     </ul>
    </div>
   </footer>

  <!-- Scripts -->
   <script src="assets/js/jquery.min.js"></script>
   <script src="assets/js/jquery.poptrox.min.js"></script>
   <script src="assets/js/skel.min.js"></script>
   <script src="assets/js/util.js"></script>
   <!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
   <script src="assets/js/main.js"></script>

 </body>
</html>

Still in the View folder but outside the Home folder, please create a php file named "My_template" as you have set in the controller. Then add the following code to call the required template fragment.

<?php
$this->load->view('Beranda/Header');
$this->load->view('Beranda/Default_main');
?>

CONGRATULATIONS! At this point your template has been integrated with CodeIgniter. You can test it by accessing the base URL: localhost/TASK2


Home / Home

6. Displaying the Northwind Database Table

This stage is still the same in principle as you create a Template page as a representative of the Home. Using the MVC concept, we can start from:

6.1 Displaying the Categories Table

Create a php file in the controller named "Categories" and the following contents:

<?php
/*
Menampilkan Tabel Categories
Oleh Wawan Beneran
bundet.com
*/
class Categories extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Categories_model','CTM'); //cara 1.

  /*
  Ada 2 cara untuk memanggil model:
   cara 1, diload disetiap class yang membutuhkannya. sebagaimana diatas.
   cara 2, diload secara otomatis di application\config\autoload.php :
   Pada line 135, Anda bisa menambahkan semacam ini:

   $autoload['model'] = array('Employee_model');
   jika sudah disebutkan disini, maka tidak perlu disebutkan lagi disetiap construct.

   Tambahan:
   $autoload['model'] = array('Employee_model'=>'em');
   'Employee_model'=>'em' -> 'em' digunakan untuk menyingkat pemangilan model di class lain
  */

 }

 public function index(){
  /*echo "<h1>Data Employees</h1>";
  $query = $this->Employee_model->get_employee();
  foreach($query->result() as $row):
   echo $row->EmployeeID.'. '.$row->FirstName ." ".$row->LastName;
   echo "<br />";
  endforeach;
  */
  $data["title"] = "<h1>Data Categories</h1>";
  $data["array_emp"] = $this->CTM->data_categories();
  $this->load->view('View_categories',$data);
 }

}

?>

Since this page has a relationship with the northwind database, we also need to create a model for it, please create a php file in the model with the name "Categories_model" with the following contents:

<?php
/*
Menampilkan Tabel Categories
Oleh Wawan Beneran
bundet.com
*/
class Categories_model extends CI_Model{

 public function data_categories(){
  $sql = "SELECT
    c.CategoryID,
    c.CategoryName,
    COUNT(*) AS jumlah
    FROM
  categories AS c JOIN products AS p
  ON c.CategoryID=p.categoryID
  GROUP BY c.categoryID";
  return $this->db->query($sql);
 }

}

?>

Create a php file in View with the name "View_categories", here are the contents:

<?php
/*
Menampilkan Tabel Categories
Oleh Wawan Beneran
bundet.com
*/
$this->load->view('Beranda/Header');

echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'No.',
'Category Name',
'Jumlah Product');

  foreach($array_emp->result() as $row):
   $this->table->add_row(
   $row->CategoryID,
   $row->CategoryName,
   $row->jumlah
   );
  endforeach;
  echo $this->table->generate();

$this->load->view('Beranda/Main');
?>

Click the Categories menu to see if your code is working properly.


Categories view works smoothly - Good job!

6.2 Displaying the Customers Table

Create a controller file with the name "Customers" and the following contents:

<?php
/*
Menampilkan Tabel Customers
Oleh Wawan Beneran
bundet.com
*/
class Customers extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Customers_model','CSM'); //cara 1.

 }

 public function index(){
  $data["title"] = "<h1>Data Customers</h1>";
  $data["array_emp"] = $this->CSM->get_customers();
  $this->load->view('View_customers',$data);
 }

}
?>

Create a model file with the name "Customers_model" and the following contents:

<?php
/*
Menampilkan Tabel Customers
Oleh Wawan Beneran
bundet.com
*/
class Customers_model extends CI_Model{

 public function get_customers(){
  return $this->db->get("customers"); //cara 1

 }
}
?>

Create a view file with the name "View_customers" with the following content:

<?php
/*
Menampilkan Tabel Customers
Oleh Wawan Beneran
bundet.com
*/
$this->load->view('Beranda/Header');

echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'ID.',
'Company Name',
'Contact Name',
'Country',
'Phone'
);

  foreach($array_emp->result() as $row):
  $this->table->add_row(
   $row->CustomerID,
   $row->CompanyName,
   $row->ContactName,
   $row->Country,
   $row->Phone
   );
  endforeach;
  echo $this->table->generate();

$this->load->view('Beranda/Main');
?>

Click the Customers menu to see the results.


Customers view is running smoothly - good job!

6.3 Displaying the Employees Table

Create a controller file with the name "Employees" and the following contents:

<?php
/*
Menampilkan Tabel Employees
Oleh Wawan Beneran
bundet.com
*/
class Employees extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Employees_model','EM'); //cara 1.
 }

 public function index(){

  $data["title"] = "<h1>Data Employees</h1>";
  $data["array_emp"] = $this->EM->get_employee();
  $this->load->view('View_employees',$data);
 }

}

?>

Create a model file with the name "Employees_model" and the following contents:

<?php
/*
Menampilkan Tabel Employees
Oleh Wawan Beneran
bundet.com
*/
class Employees_model extends CI_Model{

 public function get_employee(){
 return $this->db->get("employees"); //cara 1
 }

}

?>

Create a view file named "View_employees" with the following contents:

<?php
/*
Menampilkan Tabel Employees
Oleh Wawan Beneran
bundet.com
*/
$this->load->view('Beranda/Header');

echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'No.',
'Full Name',
'Birth Date');

  foreach($array_emp->result() as $row):
  $this->table->add_row(
   $row->EmployeeID,
   $row->FirstName ." ".$row->LastName,
   $row->BirthDate
   );
  endforeach;
  echo $this->table->generate();

$this->load->view('Beranda/Main');
?>

Click the Empoyees menu to see the results.


Employees view is running smoothly - good job!

6.4 Displaying the Orders Table

Create a controller file with the name "Orders" and the following contents:

<?php
/*
Menampilkan Tabel Orders
Oleh Wawan Beneran
bundet.com
*/
class Orders extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Orders_model','OM'); //cara 1.
 }

 public function index(){
  $data["title"] = "<h1>Data Orders Barang</h1>";
  $data["array_emp"] = $this->OM->data_orders();
  $this->load->view('View_orders',$data);
 }

}

?>

Create a model file with the name "Orders_model" and the following contents:

<?php
/*
Menampilkan Tabel Orders
Oleh Wawan Beneran
bundet.com
*/
class Orders_model extends CI_Model{

 public function data_orders(){
  $sql = "SELECT
    orders.OrderID,
 orders.CustomerID,
 orders.OrderDate,
 orders.ShipAddress,
 orders.ShipCountry,
 customers.CustomerID,
 customers.CompanyName
    FROM orders INNER JOIN customers
 ON orders.CustomerID = customers.CustomerID";
  return $this->db->query($sql);
 }

}

?>

Create a view file named "View_orders" with the following contents:

<?php
/*
Menampilkan Tabel Orders
Oleh Wawan Beneran
bundet.com
*/
$this->load->view('Beranda/Header');

echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'Order ID',
'Customer / Company',
'Order Date',
'Ship Address',
'Ship Country');

  foreach($array_emp->result() as $row):
  $this->table->add_row(
   $row->OrderID,
   $row->CompanyName,
   $row->OrderDate,
   $row->ShipAddress,
   $row->ShipCountry
   );
  endforeach;
  echo $this->table->generate();

$this->load->view('Beranda/Main');
?>

Click the Orders menu to see the results.


The Orders view is running smoothly - good job!

6.5 Displaying the Products Table

Create a controller file with the name "Products" and the following contents:

<?php
/*
Menampilkan Tabel Products
Oleh Wawan Beneran
bundet.com
*/
class Products extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Products_model','PM'); //cara 1.
 }

 public function index(){
  $data["title"] = "<h1>Data Products</h1>";
  $data["array_emp"] = $this->PM->get_products();
  $this->load->view('View_products',$data);
 }

}

?>

Create a model file named "Products_model" with the following contents:

<?php
/*
Menampilkan Tabel Products
Oleh Wawan Beneran
bundet.com
*/
class Products_model extends CI_Model{

 public function get_products(){
 return $this->db->get("products"); //cara 1
 }

}

?>

Create a view file named "View_products" with the following contents:

<?php
/*
Menampilkan Tabel Products
Oleh Wawan Beneran
bundet.com
*/
$this->load->view('Beranda/Header');

echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'Product ID',
'Product Name',
'Quantity Per Unit',
'Stock');

  foreach($array_emp->result() as $row):
  $this->table->add_row(
   $row->ProductID,
   $row->ProductName,
   $row->QuantityPerUnit,
   $row->UnitsInStock
   );
  endforeach;
  echo $this->table->generate();

  $this->load->view('Beranda/Main');
?>

Click the Products menu to see the results.


Products view is running smoothly - good job!

6.6 Displaying the Shippers Table

Create a controller file named "Shippers" with the following contents:

<?php
/*
Menampilkan Tabel Shippers
Oleh Wawan Beneran
bundet.com
*/
class Shippers extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Shippers_model','SM'); //cara 1.
 }

 public function index(){
  $data["title"] = "<h1>Data Shippers</h1>";
  $data["array_emp"] = $this->SM->get_shippers();
  $this->load->view('View_shippers',$data);
 }

}

?>

Create a model file named "Shippers_model" with the following contents:

<?php
/*
Menampilkan Tabel Shippers
Oleh Wawan Beneran
bundet.com
*/
class Shippers_model extends CI_Model{

 public function get_shippers(){
 return $this->db->get("shippers"); //cara 1
 }

}

?>

Create a view file with the name "View_shippers" and the following contents:

<?php
/*
Menampilkan Tabel Shippers
Oleh Wawan Beneran
bundet.com
*/
$this->load->view('Beranda/Header');

echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'Shipper ID',
'Company Name',
'Phone');

  foreach($array_emp->result() as $row):
  $this->table->add_row(
   $row->ShipperID,
   $row->CompanyName,
   $row->Phone
   );
  endforeach;
  echo $this->table->generate();

  $this->load->view('Beranda/Main');
?>

Click the Shippers menu to see the results.


Shippers view is running smoothly - good job!

6.7 Displaying the Suppliers Table

Create a controller file with the name "Suppliers" and the following contents:

<?php
/*
Menampilkan Tabel Suppliers
Oleh Wawan Beneran
bundet.com
*/
class Suppliers extends CI_Controller{

 public function __construct()
 {
  parent::__construct();
  $this->load->model('Suppliers_model','SM'); //cara 1.
 }

 public function index(){
  $data["title"] = "<h1>Data Suppliers</h1>";
  $data["array_emp"] = $this->SM->get_suppliers();
  $this->load->view('View_suppliers',$data);
 }

}

?>

Create a model file with the name "Suppliers_model" with the following content:

<?php
/*
Menampilkan Tabel Suppliers
Oleh Wawan Beneran
bundet.com
*/
class Suppliers_model extends CI_Model{

 public function get_suppliers(){
 return $this->db->get("suppliers"); //cara 1
 }

}

?>

Create a view file named "View_suppliers" with the following contents:

<?php
/*
Menampilkan Tabel Suppliers
Oleh Wawan Beneran
bundet.com
*/
$this->load->view('Beranda/Header');

echo heading($title,3);
$template = array(
        'table_open'            => '<table border="1" cellpadding="4" cellspacing="0">',
        'table_close'           => '</table>'
);
$this->table->set_template($template);

$this->table->set_heading(
'Supplier ID',
'Company Name',
'Address',
'City',
'Country',
'Phone');

  foreach($array_emp->result() as $row):
  $this->table->add_row(
   $row->SupplierID,
   $row->CompanyName,
   $row->Address,
   $row->City,
   $row->Country,
   $row->Phone
   );
  endforeach;
  echo $this->table->generate();

  $this->load->view('Beranda/Main');
?>

Click the Suppliers menu to see the results.


Suppliers view is running smoothly - good job!

Mission Completed!

Real Project

  1. VIEW / DOWNLOAD  KP Web Profile Manuscript Tubing Gending Indah Magelang Using CodeIgniter
  2. VIEW / DOWNLOAD  KP Web Profile Report Tubing Gending Indah
  3. VIEW / DOWNLOAD  KKL Report Online Shop Istana Topi Jogja

Netizens

Q1: FAJAR RASIA ABADI 26 Jan 2017, 22:44:00 thx om... sorry how is the database? sorry just learning ci

A1: Hi Fajar, the database can be downloaded HERE  bro  . Happy learning!

Q2: Sir, why is there an error in the database? It can't be imported, if you look at the warning, the error is in the order_details table. Please help me. 🙁


Post a Comment

Previous Next

نموذج الاتصال