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
  • 21,564
  • 12
  • 71
  • 98
AnKing
  • 1,994
  • 6
  • 31
  • 54

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,457
  • 3
  • 24
  • 28