2013-10-22 35 views
0

我正在尝试使用last.fm api打印某个艺术家和专辑的专辑信息。我已经为api库使用了dump-autoload(所以这些类应该可用)。在我的控制器之一,LastFMController.php,我有以下几点:找不到类(使用lastfm api)Laravel 4

public function some_function() { 
     $authVars['apiKey'] = '************************'; 
     $auth = new lastfmApiAuth('setsession', $authVars); 

     $artistName= "Coldplay"; 
     $albumName = "Mylo Xyloto"; 
     $album = Album::getInfo($artistName, $albumName); 
     echo '<div>'; 
     echo 'Number of Plays: ' . $album->getPlayCount() . ' time(s)<br>'; 
     echo 'Cover: <img src="' . $album->getImage(4) . '"><br>'; 
     echo 'Album URL: ' . $album->getUrl() . '<br>'; 
     echo '</div>'; 

    } 

我有一个运行这段代码的路线。当我运行这个,我得到以下错误:

Class 'Album' not found 

任何想法我做错了什么?谢谢。

+0

你用别名?否则,一定要正确命名空间 –

回答

0

你,你是采用这种封装形式:https://github.com/fxb/php-last.fm-api

你可能已经忘记了自动加载API类:

require __DIR__ . "/src/lastfm.api.php"; 

或者你可以把它添加到composer.json,作为一个例子:

"autoload": { 
    "files": [ 
     "/var/www/yourproject/libraries/lastfm.api/src" 
    ], 
}, 

并执行:

composer dump-autoload 

编辑:

您正在使用一个包和另一个示例。 有一个在你使用包没有Album类,这里是它的一个完整的例子:

<?php 

// Include the API 
require '../../lastfmapi/lastfmapi.php'; 

// Get the session auth data 
$file = fopen('../auth.txt', 'r'); 
// Put the auth data into an array 
$authVars = array(
     'apiKey' => trim(fgets($file)), 
     'secret' => trim(fgets($file)), 
     'username' => trim(fgets($file)), 
     'sessionKey' => trim(fgets($file)), 
     'subscriber' => trim(fgets($file)) 
); 
$config = array(
     'enabled' => true, 
     'path' => '../../lastfmapi/', 
     'cache_length' => 1800 
); 
// Pass the array to the auth class to eturn a valid auth 
$auth = new lastfmApiAuth('setsession', $authVars); 

// Call for the album package class with auth data 
$apiClass = new lastfmApi(); 
$albumClass = $apiClass->getPackage($auth, 'album', $config); 

// Setup the variables 
$methodVars = array(
     'artist' => 'Green day', 
     'album' => 'Dookie' 
); 

if ($album = $albumClass->getInfo($methodVars)) { 
     // Success 
     echo '<b>Data Returned</b>'; 
     echo '<pre>'; 
     print_r($album); 
     echo '</pre>'; 
} 
else { 
     // Error 
     die('<b>Error '.$albumClass->error['code'].' - </b><i>'.$albumClass->error['desc'].'</i>'); 
} 

?> 
+0

我实际上使用这个软件包:https://github.com/matto1990/PHP-Last.fm-API/ – user1072337

+0

我也用dump-autoload已经 – user1072337

+0

看看我的编辑。 –