CakePHP

How to call controller’s method from within the View in CakePHP

Although this is the not CakePHP way to call controller’s method from within the view file, but if no other way then its possible to call controller’s method directly in view.

Assuming controller name as EmployeesController.php and method name as get_employee_list something as given below:

public functions get_employee_list($department_id){
// code here
}

You can use below script to call above function in view:

App::import('Controller', 'Employees');
$EmpCont = new EmpController;
$department_id = 4 ; // put here department ID as per your need
$employee_list = $EmpCont -> get_employee_list($department_id );

Let me know if you have any query, thanks.

Comment here