CodeIgniter Forums

Full Version: Functions from external classes not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]A_funs[/eluser]
Hi,

So I am trying to use some external classes for my login system. The classes are in a directory off the root folder, not within the codeigniter application directory. Using the following code I get this message - the include resolves fine but for some reason the function won't run:

"Fatal error: Call to undefined function protect()"

Code:
include_once('xxxxx/check.class.php');
protect("1, 2, 3");

I have also tried instantiating the class in the included file

Code:
include_once('xxxxx/check.class.php');
$login = new Check();

This returns an error saying the class is not defined. Both the class and function are clearly defined in the included file...Thanks for your help

El Forum

[eluser]Aken[/eluser]
What does your class file look like?

El Forum

[eluser]PhilTem[/eluser]
It will work with including other classes if you include them correctly. And from what you're saying it's a wrong path that you're using in include Wink

Maybe you wanna try an absolute path instead of a relative one?!

El Forum

[eluser]A_funs[/eluser]
tried both absolute and relative, I am pretty sure the file is being included though, since I tried a dummy filename and received an error saying the standard "cannot open stream" - which I am not getting when I include the file.

I will post the class soon

El Forum

[eluser]PhilTem[/eluser]
How bout you replace the content of the file with something like

Code:
<?php

die('here we are');

and see if it works?

If you will see the output 'here we are' it's at least not a problem of not finding the file but something within the class.

Oh, btw: Does the file have a closing PHP-tag at the end? Don't think this is the problem, but may be - and CI recommends not using closing tags Wink

El Forum

[eluser]CroNiX[/eluser]
[quote author="A_funs" date="1342711564"]The classes are in a directory off the root folder, not within the codeigniter application directory.[/quote]
Code:
include_once('xxxxx/check.class.php');

assumes xxxxx is at the same level as index.php.

Where are you including check.class.php from?

El Forum

[eluser]CroNiX[/eluser]
And personally, I'd turn your code into a library that integrates with CI so you can use its loader, sessions, database, and everything else.