I'm using PHP's built-in DOMDocument() class to do some simple web-scraping. However, it works on my 4.2 site, but not my 5.1 (both are on same installation of PHP).
Here's the error:
Class 'App\Http\Controllers\III_Ranks\DOMDocument' not found
Here's my controller:
<?php
namespace App\Http\Controllers\III_Ranks;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class RanksController extends Controller
{
public function getRanks()
{
$list1 = new DOMDocument();
//etc...
}
}
I figure this is a namespace issue, but I have no idea how to access DOMDocument()
Thanks for any help.
In Laravel 5.1 you must prefix the class name with the global namespace prefix '\'.
So your updated code:
<?php
namespace App\Http\Controllers\III_Ranks;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class RanksController extends Controller
{
public function getRanks()
{
$list1 = new \DOMDocument();
//etc...
}
}
For me, in order to solve the error: DOMDocument() class not found
. I had to install the DOM extension.
If you are using PHP 5:
You can do so on Debian / Ubuntu using:
sudo apt-get install php5-dom
And on Centos / Fedora / Red Hat:
yum install php-xml
If you are using PHP 7:
For Ubuntu:
apt-get install php7.0-xml
For CentOS / Fedora / Red Hat:
yum install php70w-xml
Tested in Laravel 5.4
you can use keyword use
:
In top of file before define the class you can write use DOMDocument;
instead of new \DOMDocument();
For eg:
<?php
namespace App\Http\Controllers\III_Ranks;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use DOMDocument;
class RanksController extends Controller {
...
what is this '...' ?
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