-
Notifications
You must be signed in to change notification settings - Fork 333
Method Chaining
cryogenix edited this page May 20, 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(array('id', 'name', 'age'))
->from('tbl_profile')
->using('id')
->join('tbl_local', array('country'), 'tbl_profile.local_id = tbl_local.id')
->join('tbl_states', array('state'), 'tbl_profile.state_id = tbl_states.id')
->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>', array('tbl_profile.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>', array('tbl_profile.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>', array('tbl_profile.id'));
$data['result'] = $this->datatables->generate();
$this->load->view('ajax', $data);
}