我想本地使用和Slim框架(而不是Laravel)。前哨对象工作正常(我使用Sentinel::register方法时没有问题),但是当我使用Activation (例如Activation::create()方法)时,收到以下错误:
在第210行的...\vendor\illuminate\support\Facades\Facade.php中对非对象调用成员函数create()
这是我的密码:
$data = Sentinel::register($credentials);
$user = Sentinel::findById($data['id']);
$activation = Activation::create($user);这是我的composer.json的一部分:
"require": {
"slim/slim": "^2.6",
"entomb/slim-json-api": "dev-master",
"symfony/http-foundation": "^2.7",
"swiftmailer/swiftmailer": "^5.4",
"respect/validation": "^0.9.3",
"cartalyst/sentinel": "^2.0",
"illuminate/database": "^5.1",
"illuminate/events": "^5.1"
},谢谢
发布于 2016-12-20 08:27:47
这是因为Sentinel提供的Activation仅由Laravel直接支持,而不支持本地Laravel/数据库库,原因很奇怪。
如果可能的话,可以考虑使用Sentry。它也是由Cartalyst制作的,本质上是相同的库,功能较少,但似乎总体上比Sentinel更少but和更好地管理依赖。它还有更可靠的总体文档。
编辑:您可以通过替换.
Activation::与Sentinel::getActivationRepository()
发布于 2015-09-12 16:11:24
因此,如果我们看一下您得到的错误消息:
Call to a member function create() on a non-object in ...\vendor\illuminate\support\Facades\Facade.php on line 210“非对象”是您的$user变量。在我看来,Sentinel::findById($data['id']);应该通过查找提供的id返回一个表示用户的对象。不管出于什么原因,它都找不到那个用户,所以它可能会返回null或false。如果这对于您的应用程序来说是可以接受的行为,那么您可以这样做:
$data = Sentinel::register($credentials);
$user = Sentinel::findById($data['id']);
if ($user){
// The user was successfully found
$activation = Activation::create($user);
} else {
// Generate an error/exception/message here indicating that the user could not be found, or take them to the 404 page, etc.
...
}对于您的应用程序,我不知道它在else情况下应该做什么。
发布于 2021-06-14 10:36:42
只要用,它就像那样和我一起工作:
$data = Sentinel::register($credentials);
$user = Sentinel::findById($data['id']);
$activation = Sentinel::activate($user);如果是好的返回1,如果没有返回空的。
https://stackoverflow.com/questions/32529515
复制相似问题