Selasa, 01 Mei 2012

MEMBUAT FILE KONFIGURASI SENDIRI PADA CODEIGNITER


1. buat file baru didalam folder application -> config. ex : common_config.php

-----------------common_config.php-------------------------------------
$config['project_name']     = 'SCIP System';
$config['project_title']    = 'Supply Chain Integrated Program';
$config['system_version']   = 'v.1';
$config['date_version']     = '15 January 2011';
$config['programmer']       = "Muhamad Yanun As'at";
$config['company']          = 'PT. PERTAMINA (Persero) RU-IV - Cilacap';
------------------------------------------------------------------------

2. buat file baru pada folder application -> helpers. ex : common_helper.php
    kenapa harus dengan _helper, hal itu karena file yang diletakkan didalam folder helpers harus diikuti
    dengan  _helper agar bisa dipanggil oleh sistem.

-----------------------common_helper.php------------------------------------------------------------
/**
 * Project name
 *
 * Returns the "project_name" from your common_config file
 *
 * @access public
 * @return string
 */
if ( ! function_exists('project_name'))
{
function project_name()
{
$CI =& get_instance();
return $CI->config->item('project_name');
}
}


/**
 * Project Title
 *
 * Returns the "project_title" from your common_config file
 *
 * @access public
 * @return string
 */
if ( ! function_exists('project_title'))
{
function project_title()
{
$CI =& get_instance();
return $CI->config->item('project_title');
}
}


/**
 * System Version
 *
 * Returns the "system_version" from your common_config file
 *
 * @access public
 * @return string
 */
if ( ! function_exists('system_version'))
{
function system_version()
{
$CI =& get_instance();
return $CI->config->item('system_version');
}
}


/**
 * Date Version
 *
 * Returns the "date_version" from your common_config file
 *
 * @access public
 * @return string
 */
if ( ! function_exists('date_version'))
{
function date_version()
{
$CI =& get_instance();
return $CI->config->item('date_version');
}
}

/**
 * Programmer
 *
 * Returns the "programmer" from your common_config file
 *
 * @access public
 * @return string
 */
if ( ! function_exists('programmer'))
{
function programmer()
{
$CI =& get_instance();
return $CI->config->item('programmer');
}
}

/**
 * University
 *
 * Returns the "company" from your common_config file
 *
 * @access public
 * @return string
 */
if ( ! function_exists('company'))
{
function company()
{
$CI =& get_instance();
return $CI->config->item('company');
}
}
---------------------------------------------------------------------------------------------------------

3. setelah selesai membuat filenya, selanjutnya tinggal memanggil file-file tersebut. caranya adalah dengan
    mengedit file autoload.php pada folder application -> config

   a. bagian pertama yang perlu diedit adalah :

      $autoload['helper'] = array('common');

      klo dilihat pada nama yang ada didalam kurung array adalah common bukan common_helper. hal ini
      karena untuk _helper akan ditambahkan secara otomatis oleh sistem.


   b. bagian kedua yang perlu untuk diedit adalah :

      $autoload['config'] = array('common_config');

      setelah melakukan edit pada autoload helper,selanjutnya adalah melakukan edit pada autoload config.
       kenapa yang diedti dari tadi adalah file autoload dan bukan file yang lainnya. ini karena kita inginkan  
       agar file-file yang telah dibuat tadi dipanggil secara otomatis oleh sistem. setelah selesai diedit simpan file
       tersebut.

4. selanjutnya akan dicoba untuk memanggil salah satu fungsi yang telah dibuat tadi. caranya adalah dengan
    memanggil nama dari fungsi yang mau dipanggil.

   ex : project_title();

   hasilnya adalah :  Supply Chain Integrated Program











1 komentar: