Welcome Guest, Not a member yet? Register   Sign In
Very Strange Issue
#1

[eluser]neen[/eluser]
I am loading up a 3rd party library for integration with IPB (I'm using IPBWI version 2.0.4).

For some very strange reason, the library is being loaded twice (or at the very least, the db connect function is running twice)! This library connects to a database using the IPB connection...well, when it tries to load up a second time, the database information (username/pw/database name) aren't retrieved for some reason, and I'm really stumped here!

I've verified that it is indeed running twice by putting a print 'test' inside the library. This behavior only happens when it's loaded up with CI (not when it's loaded by itself). This happens when the library is loaded in autoload.php as well as when it is loaded inside the __construct() function of my controller...

Does anyone have any ideas or suggestions as to what may be causing my issue? I've started from a fresh download of 1.7, and tried only loading this one library and the behavior still happens.
#2

[eluser]TheFuzzy0ne[/eluser]
Not without seeing the code you're using.

I'm going to download it now and set it up, then I'll report back to you.
#3

[eluser]TheFuzzy0ne[/eluser]
At the bottom of ipbwi.inc.php, there are these lines:

Code:
if(empty($ipbwi)){
    $ipbwi = new ipbwi();
}else{
    die('<p>Error: You have to include and load IPBWI once only.</p>');
}

The class is automatically instantiated when it's included. Removing that line (in theory) should fix it for you, but I wouldn't recommend it in case some other part of the class relies on the $ipbwi global.

Hope this helps.
#4

[eluser]neen[/eluser]
Hmm..well, my ipbwi.php file has a require_once() in it - and that's it...so I'm guessing CI automatically instantiates the class, then?

Guess so - I've commented out those last lines. As far as I know, that is just there for convenience.
#5

[eluser]TheFuzzy0ne[/eluser]
Yes. CodeIgniter instantiates the class for you. Ideal for libraries that you only need one instance of, but not so great for objects that require more than one instance.

Has this solved your problem?
#6

[eluser]neen[/eluser]
It does indeed seem to have worked..thanks for the help - I probably never would have realized this on my own.
#7

[eluser]TheFuzzy0ne[/eluser]
Always a pleasure! Smile

I'm a huge admirer of how CodeIgniter is structured and coded, so I've spent a lot of time picking it to pieces to try to understand the inner-workings, and teaching myself a thing or two about simplicity and elegance. I don't think I'd use another framework if someone paid me!

Good luck with your application.
#8

[eluser]beerguide_au[/eluser]
Can you guys please elaborate a little on how to do this?

Sorry for sounding so green, but I am. This is my first real use of CodeIgniter and I'm trying to integrate IPBWI also. I have put ipbwi.inc.php in my /helper folder and renamed it ipbwi_helper.php and loaded it in my controller using $this->load->helper(ipbwi)

I am then trying to check if the member is logged in, in my controller, and set a session variable appropriately, code follows:

Code:
/** Set Data **/
if ($ipbwi->member->isLoggedIn()) {
$member = $ipbwi->member->info();
$this->session->set_userdata(array('display_name'=>$member['member_display_name'],'logged_in'=>TRUE));
}

The error I am receiving is:

Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined variable: ipbwi
Filename: controllers/welcome.php
Fatal error: Call to a member function isLoggedIn() on a non-object

I am obviously doing something wrong, but I am not sure where to start and I am hoping you guys can help me out.
#9

[eluser]TheFuzzy0ne[/eluser]
How are you loading/instantiating the class? Are you just including it?

If you include it within your controller constructor, it will be within the constructor scope, so you can do something like this:

Code:
include(APPPATH.'libraries/ipbwi'.EXT); # Or whatever the path is
$this->ipbwi =& $ipbwi;

Then you should be able to access it from anywhere within your controller using $this->ipbwi.

Hope this helps.
#10

[eluser]garymardell[/eluser]
Code:
$this->load->helper(ipbwi)

should be

Code:
$this->load->helper("ipbwi");

you mentioned that line in your post. Not sure if its related or you just couldnt be bothered to type it fully.




Theme © iAndrew 2016 - Forum software by © MyBB