0
votes

i try load custom helper but it is not load and generate error like this

An Error Was Encountered

Unable to load the requested file: helpers/getdata_helper.php

my helper is stored in

Application/helper/getdata.php

my controller is

class home extends CI_Controller
{
    
    public function __construct()
    {
        parent::__construct();  
        $this->load->model('home_model');
        $this->load->helper(array('url','form','language','string'));  
      $this->load->helper('getdata');
        //$this->EE->load->helper('menu_load'); 
    }   
    public function index()
    {   
        $menu['menu']=$this->home_model->get_menu();         
        $menu['print_menu']=$this->echoMenu($menu['menu']);

        $data['latest']=$this->home_model->get_latest_product();    
        $this->load->view('header_1',$menu);
        $this->load->view('index',$data);
        $this->load->view('footer');
    }
2
Your helper file name should be Application/helper/getdata_helper.php. - Ariful Haque
I agree with the comment above.. in addition, you don't need to load getdata by itself, you can place it in the array where you're loading all the other helpers. Also, if you are planning to use these helpers all over your site you might want to consider autoloading them in application\config\autoload.php - CodeGodie

2 Answers

1
votes

Let's see what des doc says :

Loading a helper file is quite simple using the following function: $this->load->helper('name');

Where name is the file name of the helper, without the .php file extension or the "helper" part.

For example, to load the URL Helper file, which is named url_helper.php, you would do this: $this->load->helper('url');

It clearly suggests that CI will look for a file named xxx_helper.php. In you case, when load getdata, CI will look for getdata_helper.php inside application/helpers .

You just have to rename your file to make it work.

-1
votes

It shouldn't give a error. Anyways try to auto load it like:

$autoload['helper'] = array('getdata');