2016-11-29 45 views
0

我想解析一個XML。 我所著此ResultControllerClass'App Http Controllers Illuminate Container Container'找不到

<?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'); 
    } 


} 

我用使用照亮\容器\容器;在控制器的頂部,但它給了我這個錯誤:

FatalErrorException in ResultController.php line 13: Class 'Illuminate\Container\Container\Controller' not found.

我不明白它有什麼問題嗎?

+0

'$ app = new \ Illuminate \ Container \ Container;'應該可以工作 – Sherif

回答

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); 

As you've used new Illuminate\Container\Container the php would find your container as - App\Http\Controllers\Illuminate\Container\Container , which isn't the correct path, the use keyword helps php to recognize the namespace of class Container

欲瞭解更多信息請參閱PHP Namespacing Docs

希望這會有所幫助!

+0

是的。這是答案。但如何可以使用$ document = new Orchestra \ Parser \ Xml \ Document($ app);當我在上面使用它? – mrmrn

+0

看到我上面更新的答案,希望它能解決您的問題! –