Welcome Guest, Not a member yet? Register   Sign In
Help! I have a recursion in my CI-Object.
#1

[eluser]RedFin[/eluser]
Hello Guys,

I'm new to CI and need a little help here. I have the following setup:

Code:
class MY_Controller extends CI_Controller {
which is most likely my Front-Controller loading all the important stuff i need later. In MY_Controller, there is stuff like:
Code:
$this->load->library('some-self-written-library');
print_r($this);

Now i want to retrieve the current CI-Object in one of my self-written libraries, e.g:

Code:
class some-self-written-library {


public function __construct()
{
  //retrieve current framework instance
  $CI =& get_instance();
  $CI->load->library('encrypt');

If i now print_r $this (like shown above), there is the following "problem":

Code:
Company Object
(
    [data:protected] => Array
        (
        )

    [benchmark] => CI_Benchmark Object
        (
            [marker] => Array
                (
                    [total_execution_time_start] => 0.20528900 1348497221
.
.
.

                )

        )
.
.
.

      [encrypt] => CI_Encrypt Object
        (
            [CI] => Company Object
*RECURSION*
            [encryption_key] =>
            [_hash_type] => sha1
            [_mcrypt_exists] =>
            [_mcrypt_cipher] =>
            [_mcrypt_mode] =>
        )

)
where Company is the current Controller i was loading. Does that mean, that i have a complete new CI-Object IN the already existing CI-Object?

How can i solve this problem, or shorter: How can i access the current ci-instance in a self-written library without creating that kind of recursion. Any ideas?

I also noticed that this only happens if i load librarys inside of a self-written library.
How do i solve this, if i need libraries inside of libraries? Smile

Kind regards
John.

#2

[eluser]PhilTem[/eluser]
You won't be able to avoid that recursion. That's how CI was designed. It should actually happen in anything code that you create i.e. also models and controllers.
If you need libraries inside libraries - which isn't bad at all - just do it as you got your code posted in your thread. There's no way to avoid this because this is how CI is written (just have a look at the Loader-class to understand how models, controllers, or libraries are being loaded and instantiated, then you will also understand why you get that recursion Wink )
#3

[eluser]RedFin[/eluser]
Thanks PhilTem Smile




Theme © iAndrew 2016 - Forum software by © MyBB