CodeIgniter Forums
Functions from external classes not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Functions from external classes not working (/thread-53329.html)



Functions from external classes not working - El Forum - 07-19-2012

[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


Functions from external classes not working - El Forum - 07-19-2012

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


Functions from external classes not working - El Forum - 07-19-2012

[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?!


Functions from external classes not working - El Forum - 07-19-2012

[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


Functions from external classes not working - El Forum - 07-19-2012

[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


Functions from external classes not working - El Forum - 07-19-2012

[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?


Functions from external classes not working - El Forum - 07-19-2012

[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.