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.
In the controller
$this->load->helper('user_helper');
user_helper.php
function getUserDetails($userId=NULL,$field='') { $CI =& get_instance(); $mod = $CI->load->model('user_model'); $conditions = array('users.id'=>$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
getUserDetails($user_id,'user_name')
That’s all!