Welcome Guest, Not a member yet? Register   Sign In
Using Helpers inside own Libraries
#1

[eluser]uk81[/eluser]
Hi.

I have a little problem.
It is more a problem with the documentation than with the code itself.

I load the url-helper inside my own library like the documentation shows:
http://ellislab.com/codeigniter/user-gui...aries.html (s. Utilizing CodeIgniter Resources within Your Library)

So I load the helper with:
Code:
$this->ci =& get_instance ();
$this->ci->load->helper('url'); //this works fine

and then use it with:
Code:
$this->ci->anchor ();
or
Code:
$this->ci->base_url ();



This is how it is explained in the documentation, but does not work in this way. I was testing and trying and now found out that I use it in a other Library already in this way, totally different from explained in the documentation:
Code:
anchor ();
or
Code:
site_url ();

It is totally confusing, because the documentation seems to be false or I make something totally false. If noone can explane it to me or knows why it works in that way, I will report a documentation bug.

Thanks. Smile
#2

[eluser]xwero[/eluser]
the $this->ci-> syntax is used when you load a model or library and use the methods of them. A helper is a file with functions in it.
#3

[eluser]uk81[/eluser]
Ah I see ... I oversee, that helpers, libraries and models are also used inside a library as they will be used in a controller.
Only when the instance is called (in a controller with $this->) the variable as a reference to the instance inside the library is used.

My fault. Smile




Theme © iAndrew 2016 - Forum software by © MyBB