【发布时间】:2019-11-08 15:42:39
【问题描述】:
我的控制器中有以下代码,基本上是尝试使用我通过 composer 安装的this 库
use Symfony\Component\HttpFoundation\Response;
require __DIR__.'/../../vendor/autoload.php';
class MainController
{
public function number()
{
$username = 'someusername';
$password = 'somepassword';
$debug = true;
$truncatedDebug = false;
$ig = new \InstagramAPI\Instagram($debug, $truncatedDebug);
$number = random_int(0, 100);
return new Response(
'<html><body>Lucky number: '.$number.'</body></html>'
);
}
}
但是它给了我以下内容
Attempted to load class "Instagram" from namespace "InstagramAPI".
Did you forget a "use" statement for another namespace?
我尝试添加 use namespace Instagram ,但没有成功
【问题讨论】:
-
如果您注释掉
Instagram行,您是否会收到与Response相同的错误? -
您是否使用文档中显示的 composer require 命令安装?并且已经在下面指出,由于框架会处理它,因此无需再次要求 autoload.php。
-
出于好奇,我运行了“composer require mgp25/instagram-php”,它似乎都安装了。必须安装 php bcmath 扩展。并且 instagram 包安装了一堆依赖项。但这一切都按预期进行。因此,请仔细检查您的安装是否没有错误。
标签: php symfony composer-php