I am trying to load the Simple HTML DOM Parser in my Laravel-4
project. However, I can't get it to find the class. I am getting this error:
Class 'Libraries\SimpleHtmlDom\simple_html_dom_node' not found
I've put simple_html_dom.php
in app\libraries
and
namespace Libraries\SimpleHtmlDom;
in the top of simple_html_dom.php
.
In global.php
I've added the libraries
folder:
ClassLoader::addDirectories(array(
app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
app_path().'/libraries',
));
And finally, in my controller, I am trying to instantiate it:
$parser = new Libraries\SimpleHtmlDom\simple_html_dom_node;
What am I doing wrong?
To (hopefully) solve your problem without changing your current structure, you may just need to run:
$ composer dump-autoload
Or you may need to add an autoloaded section in composer.json
along with the others:
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/libraries"
]
},
And then run composer dump-autoload
again.
It looks like there's a Composer package you could be using instead: https://packagist.org/packages/sunra/php-simple-html-dom-parser
This makes adding it to your project easier:
A. Add dependency to composer.json
(either via this CLI call or by adding manually to your composer.json file):
# Run this command:
$ composer require "sunra/php-simple-html-dom-parser": "1.5.0.*@dev"
B. Use new package in your code
$dom = HtmlDomParser::file_get_html( $file_name );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With