doushan1850
2015-07-23 03:16
浏览 212
已采纳

Laravel 5.1 PHP DOMDocument()类未找到

I'm using PHP's built-in DOMDocument() class to do some simple web-scrapping. 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.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

5条回答 默认 最新

  • duan7264 2015-07-23 03:57
    最佳回答

    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...
        }
    }
    
    评论
    解决 无用
    打赏 举报
查看更多回答(4条)

相关推荐 更多相似问题