How to use the libraries and helpers in Codeigniter

library or libraries are collections and functions provided by CodeIgniter. past library CodeIgniter provides functions here that can be used when creating websites. For example library for access to the database, library send Email, library for validation entry and other.

Also read:

To use a library, the library must first be loaded into the controller that will use it.

$this -load -library(‘[nama_library]’);

For example if you want to use Library validation so library It must beload First.

 $this -load -library(‘validation’);

If you want me-Load a number of library at the same time can be done by inserting into an array.

$this -load -library(array(‘[library1]’,’library2’));

For example, do you want toLoad validation library and date so.

$this -load -library(array(‘validation’,’date’));

Apart from-load manually Controllers, libraries that you want to use can also beload automatically so that it can be used on all Regulator by adding it to the array in the autoload.php file

$autoload['libraries'] = array();

example for Load validation library and date automatically.

$autoload['libraries'] = array(‘validation’,’date’);

The following is an example of the use of the library and the helper in the following program excerpts:

1. The first step is to Files by doing Regulator by name welcome.php.

2. Then enter the following program section in the file welcome.php.

How to use libraries and helpers in Codeigniter

load->helper('html'); //fungsi untuk memanggil helper html $list = array( 'red', 'blue', 'green', 'yellow' ); $this->load->library('table'); //fungsi untuk memanggil libary table $tmpl=array('table_open'=>'','table_close'=>'table->set_template($tmpl); $this->table->set_caption('Colors'); $this->table->set_heading('Name','Color','Size'); $this->table->add_row('Fred', 'Red', 'Large'); $this->table->add_row('Ginny', 'Pink', 'Small'); $this->table->add_row('Ron', 'Blue', 'Medium'); $a= $this->table->generate(); $data['table']=$a; $data['list_warna']=ul($list); $data['heading']=heading('Biodata Diri',1); $data['nama']="Yunan Helmi Al Anbarry"; $data['npm']="59413587"; $list = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'); $new_list = $this->table->make_columns($list, 6); $b=$this->table->generate($new_list); $data['kolom']=$b; $this->load->view('view_html',$data); } } ?>

3. When the controller welcome.php has been formed, now it’s time to create a file view_htm.php in the folder View.

  Latihan Library   

Nama :

NPM :

List Warna :


4. Now open your browser and enter the URL http: // localhost / CI /. If successful, you will see a page like this:

How to use libraries and helpers in Codeigniter 2

Well, that’s the benefit of using it helper and library when creating the page website on code detonator. In summary, it can be said that using the Codeigniter framework can simplify and reduce working hours programmer in the making Web pages.






Leave a Reply

Your email address will not be published.