Welcome Guest, Not a member yet? Register   Sign In
Bug in extended helpers?
#1

[eluser]olof84[/eluser]
Hi!

It seems to me that my extended helpers are available through out all my CI, without me having loaded the helpers. Have I done something wrong, or do you guys have the same experience?

I have tried extended the url and string helper (MY_url_helper, My_string_helper).

EDIT: I have not auto-loaded the helpers.
#2

[eluser]jonez[/eluser]
If you're auto-loading those helpers then yes, they would be available everywhere.
#3

[eluser]olof84[/eluser]
I forgot to wrote, I have not auto-loaded the extended helpers. They are available anyhow. I can't figure out what could be wrong. Maybe it is a bug in CI?
#4

[eluser]jonez[/eluser]
I doubt it's a bug. Are you using __autoload?
#5

[eluser]olof84[/eluser]
No, not what I am aware of.
#6

[eluser]jonez[/eluser]
CI doesn't load any helpers by default so something in your code is loading them. Try searching your project for load calls for those helpers or __autoload.
#7

[eluser]olof84[/eluser]
It´s just the extended helpers that seem to be globally available in my project. I have searched my project for calls to both the extended helpers and __autoload and no match found.
#8

[eluser]CroNiX[/eluser]
There is nothing in CI's code that will load a helper without you specifically doing it. It only looks for an extended helper (or controller, or model) if you specifically load the base helper (or controller or model).
Like it won't ever look for /helpers/MY_url_helper.php unless you try to load the regular url helper. You'd never load the "MY_url_helper" manually, only the regular url helper which will load the extended helper if it exists.

It could be you're doing it in MY_Controller (if you use that), a controllers construct, or a library that you are using. So if you are using libraries, or autoloading them, especially custom libraries, I'd check those as well to see if those are loading any helpers.

I'd use your IDE's search function and do a keyword search of all files in your project and look for instances of "load->helper" (leave $this off in case you are using a CI instance via get_instance()).
#9

[eluser]olof84[/eluser]
Thanks for replying. I have done what you suggested. I am using NetBeans so I know how to search my project.

I think it might be an small bug. Try this:

1. Make an extended helper (for an helper which you have not auto-loaded), for example: MY_string_helper.
2. Make an function inside your extended helper.
3. Call the function test() from one of your controllers.

See the result!
#10

[eluser]CroNiX[/eluser]
I just did that, and it gave a fatal error as expected.

Repeatable steps I took:
1) Downloaded fresh CI 2.2 from this site and unzipped in /public_html/CI2_test. Nothing was altered except what is mentioned below. There is no .htaccess and all settings are the default settings.
2) Went to http://localhost/CI2_test in a browser and saw the default CI "welcome" message
3) Created /application/helpers/MY_url_helper.php
Code:
if ( ! function_exists('test_url'))
{
function test_url()
{
  echo 'this is test_url from MY_url_helper';
}
}
4) changed default controller, /application/controllers/welcome.php, and called the new helper function WITHOUT loading the url helper first. There is nothing autoloaded, either. This is a stock CI install.
Code:
class Welcome extends CI_Controller {

public function index()
{
  test_url();
}
}
5) In browser, went to http://localhost/CI2_test and got the expected error:
Code:
Fatal error: Call to undefined function test_url() in /public_html/CI2_test/application/controllers/welcome.php on line 8
6) Changed /application/controllers/welcome.php and loaded the url helper before the new function call
Code:
class Welcome extends CI_Controller {

public function index()
{
  $this->load->helper('url');
  test_url();
}
}
7) In browser, went to http://localhost/CI2_test and got the expected result:
Code:
this is test_url from MY_url_helper

So, it is not doing what you stated and works as intended.




Theme © iAndrew 2016 - Forum software by © MyBB