从composer添加的包中调用未定义的方法 [英] Call to undefined method from composer added package
本文介绍了从composer添加的包中调用未定义的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在我的Laravel 5应用中尝试使用 SlackBot类
I'm trying to use SlackBot class with my Laravel 5 app.
但是我遇到了这个错误:
But I'm getting this error:
Call to undefined method Mpociot\SlackBot\Facades\SlackBot::initialize()
这是我的控制者:
use SlackBot;
public function slack_bot()
{
$slackbot = new SlackBot();
$slackbot->initialize('xoxb-XXX');
}
我试图调试哪些可用的方法:
I tried to debug which methods are available with this:
$methods = get_class_methods($slackbot);
print_r($methods);
我明白了:
Array ( [0] => swap [1] => shouldReceive [2] => getFacadeRoot [3] => clearResolvedInstance [4] => clearResolvedInstances [5] => getFacadeApplication [6] => setFacadeApplication [7] => __callStatic )
which is very different from the methods defined in github class]2.
我该如何解决?
我做了什么:
我正在关注教程
我运行作曲家需要mpociot/slackbot
I ran composer require mpociot/slackbot
然后我将config/app.php添加到服务提供商:
And then I added to config/app.php the service provider:
Mpociot\SlackBot\SlackBotServiceProvider::class,
以及别名/facade:
and the alias / facade:
'SlackBot' => Mpociot\SlackBot\Facades\SlackBot::class
推荐答案
您将获得 Facade 的实例,而不是真实类.
You're getting a instance of the Facade instead of the real class.
替换您的
$slackbot = new SlackBot();
$slackbot->initialize('xoxb-XXX');
使用:
$slackbot = SlackBot::initialize('token');
这篇关于从composer添加的包中调用未定义的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文