Skip links

CodeIgniter fetch data to the view without controller

How to direct call to the function from the view without using controller in CodeIgniter.Here is a example to it.Simply call to helper function and it get data from model.
First you load helper file from your controller.

[stextbox id=”info” bgcolor=”bacafb”]A helper class is a set of functions. These helper functions can help a library or any other type of function that you want to use over and over again in your code.[/stextbox]
In the controller



function getUserDetails($userId=NULL,$field='')
   $CI =& get_instance();
   $mod = $CI->load->model('user_model');
   $conditions = array(''=>$userId);
   $result = $CI->user_model->getUsers($conditions);
   if($result->num_rows()>0) {
        $data = $result->row();
        $res = $data->$field;
   } else {
        $res = '';
return $res;

Usage in your view


That’s all!