In this tutorial you will learn about the CodeIgniter Method Chaining and its application with practical example.
What Method Chaining In CodeIgniter?
In CodeIgniter, method chaining enables us to connect multiple method calls in single statement. Method chaining simplifies the syntax required to call multiple methods sequential over single object. Each of the method returns an object, without requiring intermediate variables to hold the results. Method chaining reduces the amount of code and improves the readability of code.
Example:- Let’s say you have a MySQL table named ’employee_master’ with the following fields –
emp_ID, emp_name, emp_email, emp_phone, emp_address, emp_code and emp_dept
1 2 |
$this->db->select('emp_name')->from('employee_master')->where('emp_ID', $id)->limit(10, 20); $query = $this->db->get(); |