Articles → PHP CODEIGNITER → Add And Override Functions In Existing Library In Codeigniter
Add And Override Functions In Existing Library In Codeigniter
- Add a new function in the existing library.
- Override the existing functions in the existing library.
Example - Add A New Function In The Existing Library
<?php
class My_Table extends CI_Table
{
public function generateTable()
{
echo "This function will only display a message";
}
}
$this->load->library('table');
$data = array(
array('Name', 'Color', 'Size'),
array('Fred', 'Blue', 'Small'),
array('Mary', 'Red', 'Large'),
array('John', 'Green', 'Medium')
);
echo $this->table->generate($data);
echo $this->table->generateTable();
Click to Enlarge
Example - Override Existing Functions In The Library
<?php
class MY_Table extends CI_Table
{
public function generate($table_data = NULL)
{
echo "Calling generate";
}
}
$this->load->library('table');
$table_data = array(
array('Name', 'Color', 'Size'),
array('Fred', 'Blue', 'Small'),
array('Mary', 'Red', 'Large'),
array('John', 'Green', 'Medium')
);
echo $this->table->generate($table_data);
Click to Enlarge