Skip to content
n1crack edited this page May 30, 2011 · 4 revisions

Method chaining allows you to simplify your syntax by connecting multiple functions. Consider this example:
*method chaining only works with PHP 5

function list_all()
{
  $this->datatables
    ->select('id, name, age, gender')
    ->from('tbl_profile')
    ->join('tbl_local', 'tbl_profile.local_id = tbl_local.id')
    ->select('country')
    ->join('tbl_states', 'tbl_profile.state_id = tbl_states.id')
    ->select('state')
    ->add_column('view', '<a href="' . base_url() . 'admin/profiles/view/$1"><img src="' . base_url() . 'assets/images/admin/vcard.png" alt="View" title="View" /></a>', 'id')
    ->add_column('edit', '<a href="' . base_url() . 'admin/profiles/edit/$1"><img src="' . base_url() . 'assets/images/admin/vcard_edit.png" alt="Edit" title="Edit" /></a>', 'id')
    ->add_column('delete', '<a href="' . base_url() . 'admin/profiles/delete/$1"><img src="' . base_url() . 'assets/images/admin/vcard_delete.png" alt="Delete" title="Delete" /></a>', 'id');

  $data['result'] = $this->datatables->generate();
  $this->load->view('ajax', $data);
}
Clone this wiki locally