在codeigniter中集成为类库

时间:2014-06-24 22:23:02

标签: php codeigniter svg simplexml scale

我需要集成此线程答案中的代码。

How to rotate SVG by PHP

当我作为一个图书馆这样做时,我得到错误"构建",我对它没有太多了解,我希望你能帮助我。

1 个答案:

答案 0 :(得分:0)

从这堂课开始:

class ExSimpleXMLElement extends SimpleXMLElement 
{ 


    public function _construct($xml){
        parent::_construct($xml);
    }

    /** 
     * Add SimpleXMLElement code into a SimpleXMLElement 
     * @param SimpleXMLElement $append 
     */ 
    public function appendXML($append) 
    { 
        if ($append) { 
            if (strlen(trim((string) $append))==0) { 
                $xml = $this->addChild($append->getName()); 
                foreach($append->children() as $child) { 
                    $xml->appendXML($child); 
                } 
            } else { 
                $xml = $this->addChild($append->getName(), (string) $append); 
            }     
            foreach($append->attributes() as $n => $v) { 
                $xml->addAttribute($n, $v); 
            } 
         } 
     } 
} 

你会像这样改变它:

<?php

class ExSimpleXMLElement
{ 
    private $sxe;

    public function loadXml($xml){
        $this->sxe = new SimpleXMLElement($xml);
    }

    /** 
    * Add SimpleXMLElement code into a SimpleXMLElement 
    * @param SimpleXMLElement $append 
    */ 
    public function appendXML($append) 
    {
        if ($append) { 
            if (strlen(trim((string) $append))==0) { 
                $xml = $this->sxe->addChild($append->getName()); 
                foreach($append->children() as $child) { 
                    $xml->appendXML($child); 
                } 
            } else { 
                $xml = $this->sxe->addChild($append->getName(), (string) $append); 
            }     
            foreach($append->attributes() as $n => $v) { 
                $xml->addAttribute($n, $v); 
            } 
        } 
    } 
}

并像这样使用它:

$this->load->library('ExSimpleXMLElement');

$this->exsimplexmlelement->loadXML($xml);