Class' App \ Http \ Controllers \ Illuminate \ Container \ Container'未找到

时间:2016-11-29 14:52:24

标签: php xml laravel

我想解析XML。 我写了这个ResultController

<?php
namespace App\Http\Controllers;

use Auth;
use \App\User;
use Illuminate\Http\Request;
use XmlParser;
use Illuminate\Container\Container;
use Orchestra\Parser\Xml\Document;
use Orchestra\Parser\Xml\Reader;

class ResultController extends Controller
{

    public function getResults()
    {

        $xml = XmlParser::load('http://www.xmlsoccer.com/FootballDataDemo.asmx/GetAllTeams?ApiKey=ZXRIQOWMCFARAWRQIMSLRXCTSZDOBNLOTYWXYXMZYGDSENFSRB');
        $app = new Illuminate\Container\Container;
        $document = new Orchestra\Parser\Xml\Document($app);
        $reader = new Orchestra\Parser\Xml\Reader($document);

        $xml = $reader->load('http://www.xmlsoccer.com/FootballDataDemo.asmx/GetAllTeams?ApiKey=ZXRIQOWMCFARAWRQIMSLRXCTSZDOBNLOTYWXYXMZYGDSENFSRB');
        $user = $xml->parse([
            'users' => ['uses' => 'Team[Team_Id,Name]'],
        ]);

        // dd($xml);
        return view ('results.live');
    }


}

我用过Illuminate \ Container \ Container;在控制器的顶部,但它给我这个错误:

  

ResultController.php第13行中的FatalErrorException:Class   &#39;照亮\集装箱\集装箱\控制器&#39;没找到。

我无法理解它有什么问题?

1 个答案:

答案 0 :(得分:1)

如果您上面使用了use个关键字 -

use Illuminate\Container\Container;
use Orchestra\Parser\Xml\Document as OrchestraDocument;
use Orchestra\Parser\Xml\Reader as OrchestraReader;

你应该在方法中使用它(更新):

$app = new Container;
$document = new OrchestraDocument($app);
$reader = new OrchestraReader($document);
  

正如您使用new Illuminate\Container\Container,php会找到   你的容器是 -   App\Http\Controllers\Illuminate\Container\Container,这不是   正确的路径,use关键字帮助php识别命名空间   班级Container

有关详细信息,请参阅PHP Namespacing Docs

希望这有帮助!