CodeIgniter Forums
Include class in class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Include class in class (/showthread.php?tid=19843)

Pages: 1 2


Include class in class - El Forum - 06-20-2009

[eluser]freshface[/eluser]
Is this possible to do?

Like this:
Code:
<?php

    include 'Snoopy.class.php';

    class Extractor
    {
        function __consruct()
        {
            
        }
        
        
        public function extract($page)
        {
            Snoopy::fetchlinks($page);
            Snoopy::results;
        }
        
    }
        
?>



Include class in class - El Forum - 06-20-2009

[eluser]Dam1an[/eluser]
Yeah, although your example is assuming it's in the same directory
If not, just use the defined var APPPATH to build the correct include path


Include class in class - El Forum - 06-20-2009

[eluser]freshface[/eluser]
It works

But now i want to do this:
Code:
<?php

    include 'Snoopy.class.php';

    class Extractor
    {

        private $snoopy;
        
        function __consruct()
        {
            $this->snoopy = new Snoopy();
        }
        
        
        public function extract($page)
        {

            $this->snoopy->fetchlinks($page);
            $this->snoopy->results;

        }

But i got an error on $this->snoopy->fetchlinks($page);

Fatal error: Call to a member function fetchlinks() on a non-object in


Include class in class - El Forum - 06-20-2009

[eluser]Dam1an[/eluser]
a) Does it work if you create the snoopy object in the extract function and call the copy local to that function
b) What do you get when you do print_r on the snoopy object as soon as it's created, and just before you try to access it in the execute function


Include class in class - El Forum - 06-20-2009

[eluser]freshface[/eluser]
If i create the snoopy object inside extract there is no problem.
I just want one object so the object is available over the whole class.

print_r doesn't seem do give any feedback.


Include class in class - El Forum - 06-20-2009

[eluser]Dam1an[/eluser]
I spotted it Smile
You have a typo in the constructor, it should be __construct


Include class in class - El Forum - 06-20-2009

[eluser]TheFuzzy0ne[/eluser]
I blame Bill Gates...


Include class in class - El Forum - 06-20-2009

[eluser]Dam1an[/eluser]
[quote author="TheFuzzy0ne" date="1245544636"]I blame Bill Gates...[/quote]

Care to explain, cause this sounds like it could be good lol


Include class in class - El Forum - 06-20-2009

[eluser]freshface[/eluser]
Thanks Dam1an.

This is the thing i am working on: a little class that sniffs a whole site for links inside the same domain.
I still have a logic problem i am working out. care to take a look and help?

zip: http://www.figure8.be/problem.zip


Include class in class - El Forum - 06-20-2009

[eluser]Dam1an[/eluser]
Here's a little tip, when asking people for help, it's good to be as specific as possible. The less thinking/time wasting the other person needs to do to figure out whats going on, the better, and more likely they will help lol

So instead of saying you have a logic problem, say which file, function, maybe even line number if it's a mamoth function