Welcome Guest, Not a member yet? Register   Sign In
Unable to load the requested file
#1

[eluser]nonamez[/eluser]
I just created file /CodeIgniter/application/helpers/my_ajax_helper.php and now want to use it's functions in CodeIgniter/application/controllers/Ajax.php so i use:

Code:
function __construct(){
    parent::__construct();
    if((bool)$this->session->userdata('logged_in'))
        $this->load->helper('my_ajax');
    else
        return FALSE;
}

But error occurred:

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

What is wrong?
#2

[eluser]CroNiX[/eluser]
Helpers are regular procedural functions, not objects - so there wouldn't be a __construct or parent, or even $this. If you want to use CI within a helper or library, you need to use get_instance() to bring the instance into your function/library.

See the "Utilizing CodeIgniter Resources within Your Library" section of the library docs. It would be basically the same for a helper as far as using get_instance().


#3

[eluser]nonamez[/eluser]
no, i am trying to create my own helper file and load it in controller - is it possible?
#4

[eluser]CroNiX[/eluser]
Sure, don't use "MY", which is reserved for extending the native CI core, not your own.

rename it to just "ajax_helper.php" and call it like $this->load->helper('ajax');
#5

[eluser]nonamez[/eluser]
i tried it and without my and with my - same error.
#6

[eluser]CroNiX[/eluser]
Sorry, not sure then. Works here.

/application/helpers/ajax_helper.php

Code:
if ( ! function_exists('ajax_test'))
{
  function ajax_test()
  {
    echo 'ajax test';
  }
}

//in controller
Code:
$this->load->helper('ajax');
ajax_test();  //echos 'ajax test'
#7

[eluser]nonamez[/eluser]
Same error:

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

Where problem might be?
#8

[eluser]CroNiX[/eluser]
is your filename lower case?
#9

[eluser]nonamez[/eluser]
[quote author="CroNiX" date="1358705173"]Sorry, not sure then. Works here.

/application/helpers/ajax_helper.php

Code:
if ( ! function_exists('ajax_test'))
{
  function ajax_test()
  {
    echo 'ajax test';
  }
}

//in controller
Code:
$this->load->helper('ajax');
ajax_test();  //echos 'ajax test'
[/quote]

If it is possible please upload yours application folder with working own helper somewhere.
#10

[eluser]nonamez[/eluser]
[quote author="CroNiX" date="1358706266"]is your filename lower case?[/quote]
yes




Theme © iAndrew 2016 - Forum software by © MyBB