Welcome Guest, Not a member yet? Register   Sign In
Custom library not working
#1

[eluser]floweringmind88[/eluser]
I am doing the following to try and load and use this class:

Code:
$this->load->library('xml');
        $data = $this->xml->xml_load_file($xmlfile);

I get the following error:
Fatal error: Call to a member function on a non-object

Here is the function in the xml class:

Code:
function xml_load_file($file, $resulttype = 'object', $encoding = 'UTF-8')
    {
        $php_errormsg="";
        $this->result="";
        $this->evalCode="";
        $values="";
        $data = file_get_contents($file);
        if (!$data)
        return 'Cannot open xml document: ' . (isset($php_errormsg) ? $php_errormsg : $file);

        $parser = xml_parser_create($encoding);
        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
        xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
        $ok = xml_parse_into_struct($parser, $data, $values);
        if (!$ok) {
            $errmsg = sprintf("XML parse error %d '%s' at line %d, column %d (byte index %d)",
            xml_get_error_code($parser),
            xml_error_string(xml_get_error_code($parser)),
            xml_get_current_line_number($parser),
            xml_get_current_column_number($parser),
            xml_get_current_byte_index($parser));
        }

        xml_parser_free($parser);
        if (!$ok)
        return $errmsg;
        if ($resulttype == 'array')
        return $this->xml_reorganize($values);
        // default $resulttype is 'object'
        return $this->array2object($this->xml_reorganize($values));
    }
#2

[eluser]Tom Glover[/eluser]
It need's to with in a class called Xml, which needs to be in a file Xml.php.
#3

[eluser]floweringmind88[/eluser]
It is already in a class called Xml in a file called Xml.php in the library directory.
#4

[eluser]Tom Glover[/eluser]
You haven't wrapped the first if with {}?
#5

[eluser]floweringmind88[/eluser]
Nope that isn't it. You don't have to use brackets if you just have a 1 line if statement in php.

It is so weird because the code works if I pull it out and just pop it into my controller. Also I got phoogle for google maps to work as a library yesterday. So I find is really strange that I can't access a function in this library.

Guess I will go read docs.
#6

[eluser]Tom Glover[/eluser]
Does it require any external libs you were loading in the controller.
#7

[eluser]gtech[/eluser]
you could turn up the log threshold maybe and see if you are getting any php errors when you load the library.
#8

[eluser]Brandon Dickson[/eluser]
can you post the whole class def?

-Brandon




Theme © iAndrew 2016 - Forum software by © MyBB