CodeIgniter Forums

Full Version: calling get_instance() from external script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Yednotek[/eluser]
Is it possible to get a CI instance in an external script somehow like this:

Code:
function somefunction_in_standalone_script()
{
  $obj=&get;_instance();
}

The external script is an 3rd party script that generates an image but it uses sessions which I already use in CI. If the above is possible then this would be the easiest solution.

El Forum

[eluser]fatnic[/eluser]
I'm not sure but one solution maybe to use database sessions and then just query that table.

El Forum

[eluser]Tom Glover[/eluser]
It should be possible if you include one of the CI core files, eg index.php the call it.

El Forum

[eluser]Michael Wales[/eluser]
As long as the third-party script is called from CodeIgniter (like a controller), then yes.

El Forum

[eluser]Yednotek[/eluser]
Quote:As long as the third-party script is called from CodeIgniter (like a controller), then yes.

The script returns an image, it is placed in the src="" parameter of an image tag so it is not called from a controller.

Quote:It should be possible if you include one of the CI core files, eg index.php the call it.

If I include my main index.php in the beginning of the script, then my whole webpage is returned as output plus the image.. Is there another file I can include so that only the core CI files are loaded without returning any output?

El Forum

[eluser]Michael Wales[/eluser]
Quote:The script returns an image, it is placed in the src=”“ parameter of an image tag so it is not called from a controller.

Sounds like a helper to me, which you would load within the Controller and just call from your Views.

El Forum

[eluser]Yednotek[/eluser]
Looks like I'll have to go in that direction.. It's been a while since I coded for CI so was looking for a quick fix Wink

Thanks for the help guys!