0

In one of my models in CI i need to create a SimpleXmlElement object but I need to extend it first to use CDATA.

So I created a library:

class SimpleXMLExtended extends SimpleXMLElement
{
    public function addCData($cdata_text)
    {
        $node = dom_import_simplexml($this);
        $no = $node->ownerDocument;
        $node->appendChild($no->createCDATASection($cdata_text));
    }
}

Then in my model I load this library:

$template = $this->load->library('SimpleXMLExtended', 'xml_template.php');

But since SimpleXMLElement requires a string parameter (and codeigniter can only pass an array according to documentation) it shows error: SimpleXMLElement::__construct() expects at least 1 parameter, 0 given.

So how am I suppose to load this library?

sampathsris
  • 20,518
  • 11
  • 61
  • 93
AnKing
  • 1,644
  • 2
  • 23
  • 44

1 Answers1

1

It's not a codeigniter issue , it's how SimpleXMLElement is implemented.

This gives a very good explanation of what is happening and how to make it work.

Previous answer from Stackoverflow

Community
  • 1
  • 1
TimBrownlaw
  • 5,402
  • 3
  • 22
  • 27