【问题标题】:integrate as class library in codeigniter在 codeigniter 中集成为类库
【发布时间】:2014-08-15 08:20:37
【问题描述】:

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

How to rotate SVG by PHP

当我将它作为一个库进行时,我收到错误“construct”,我对此知之甚少,希望你能帮助我。

【问题讨论】:

    标签: php codeigniter svg simplexml scale


    【解决方案1】:

    来自这个班级:

    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);
    

    【讨论】:

    • 机器瘾君子。我尝试了代码,我得到了错误图像,可以是?我打电话给利比里亚:[链接] (docs.google.com/file/d/0B4eow_YS2Y1eVjFaQV9HRlNCcWM/edit) public function edit_svg(){ $this-&gt;load-&gt;library('ExSimpleXMLElement'); $file="images/designs/svg/a.svg"; //http://www.webdeveloper.com/forum/showthread.php?165648-Editing-XML-using-PHP $xml = simplexml_load_file($file); //Load the File. $this-&gt;exsimplexmlelement-&gt;loadXML($xml)
    • 使用$xml = file_get_contents($file);,而不是$xml = simplexml_load_file($file);loadXML 方法需要 xml 作为字符串。
    • 谢谢!,你说的工作,但现在我有另一个错误!与利比里亚相关的控制器,调用方法“appendXML()”你能帮我解决这个问题吗......我白天试图纠正它,但我没有这样做! Fatal error: Call to undefined method SimpleXMLElement::appendXML() in C:\wamp\www\m3\trunk\application\controllers\svg.php 控制器:svg 库:ExSimpleXMLElement
    猜你喜欢
    • 2016-12-12
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 2018-04-06
    • 2016-02-21
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    相关资源
    最近更新 更多