Add external libraries to Symfony2 project

前端 未结 2 721
忘了有多久
忘了有多久 2021-02-09 20:41

I am trying to add an external library (PHP Simple DOM Parser, http://simplehtmldom.sourceforge.net/index.htm) to a Symfony2 project. I took a tutorial that explains how to incl

相关标签:
2条回答
  • 2021-02-09 20:58

    You're trying to register a namespace but your class has no namespace. Try adding a namespace to it or use RegisterPrefixes().

    BTW: did you know that one of the Symfony components is basically doing the same thing as php simpledom? It's called DomCrawler and it has a support for both xpath and CSS selectors.

    0 讨论(0)
  • 2021-02-09 21:12

    I'm new to Symfony2 but as i can see, you are not respecting the PSR for autoloader.

    I'm presumable thinking you should do:

    # /vendor/phpsimpledom/lib/Phpsimpledom/Phpsimpledom.php
    
    require_once __DIR__.'/src/simple_html_dom.php';
    
    class Phpsimpledom_Phpsimpledom extends simple_html_dom_node {
    
    }
    

    Note that the correct filename would be /vendor/phpsimpledom/lib/Phpsimpledom/Phpsimpledom.php as the call must include the namespace to work.

    Hope it works now.

    0 讨论(0)
提交回复
热议问题