我已將Sentry與Composer一起安裝,因此它也安裝了Illuminate Database。安裝成功了,我已經完成了Sentry文檔中的所有工作。我試圖用簡單的代碼將用戶添加到數據庫中。然而,它給了我此錯誤消息:在使用Illuminate Database時調用非對象的成員函數連接()時出錯
Fatal error: Call to a member function connection() on a non-object in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\ilhan\vendor\illuminate\database\Illuminate\Database\Eloquent\Model.php on line 2472
我的代碼如下:
<?php
include_once "vendor/autoload.php";
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'ilhantestdb',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
]);
use Cartalyst\Sentry\Sentry as Sentry;
try
{
$user = new Sentry;
// Create the user
$user->createUser(array(
'email' => '[email protected]',
'password' => 'test',
'activated' => true,
));
// Find the group using the group id
$adminGroup = Sentry::findGroupById(1);
// Assign the group to the user
$user->addGroup($adminGroup);
}
catch (Cartalyst\Sentry\Users\LoginRequiredException $e)
{
echo 'Login field is required.';
}
catch (Cartalyst\Sentry\Users\PasswordRequiredException $e)
{
echo 'Password field is required.';
}
catch (Cartalyst\Sentry\Users\UserExistsException $e)
{
echo 'User with this login already exists.';
}
catch (Cartalyst\Sentry\Groups\GroupNotFoundException $e)
{
echo 'Group was not found.';
}
即使我不知道如何調試這一點。另外,我認爲自Illuminate自帶Sentry以來,Sentry應該被編碼爲如何處理Illuminate,因此我不需要太多配置。文檔很差,我無法找到如何處理這個錯誤。
我花了幾個小時在這!這解決了我的問題,謝謝! –