我在Laravel 4中構建了一個包,但在嘗試訪問似乎爲是一個正確實例化的對象。這裏的設置:Laravel/Eloquent:致命錯誤:調用非對象的成員函數連接()
在考慮中的配置和類:
composer.json:
...
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
"psr-0": {
"Vendor\\Chat": "src/vendor/chat/src"
}
}
...
類:
召喚:
$message = new Message($msg);
$history = new ChatHistory;
$history->create(array(
'room_token' => $message->getRoomToken(),
'user_id' => $message->getUserId(),
'message' => $message->getMessage(),
));
錯誤:
PHP Fatal error: Call to a member function connection() on a non-object in /home/vagrant/project/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 2894
我相信我失去了一些基本的東西,我的鼻子底下。感謝您的幫助!
編輯:
這裏是一個真實實例ChatHistory和調用寫入類:
namespace Vendor\Chat;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Vendor\Chat\Client;
use Vendor\Chat\Message;
use Vendor\Chat\ChatHistory;
use Illuminate\Database\Model;
class Chat implements MessageComponentInterface {
protected $app;
protected $clients;
public function __construct()
{
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn)
{
$client = new Client;
$client->setId($conn->resourceId);
$client->setSocket($conn);
$this->clients->attach($client);
}
public function onMessage(ConnectionInterface $conn, $msg)
{
$message = new Message($msg);
$history = new ChatHistory;
ChatHistory::create(array(
'room_token' => $message->getRoomToken(),
'user_id' => $message->getUserId(),
'message' => $message->getMessage(),
));
/* error here */
/* ... */
}
public function onClose(ConnectionInterface $conn)
{
$this->clients->detach($conn);
}
public function onError(ConnectionInterface $conn, \Exception $e)
{
$conn->close();
}
protected function getClientByConn(ConnectionInterface $conn)
{
foreach($this->clients as $client) {
if($client->getSocket() === $conn) {
return $client;
}
}
return null;
}
}
事實上,DB不可用暗示雄辯沒有被加載上去頂?
在哪一行中出現此錯誤?是歷史還是使用'$ message'方法。我們或當然不知道,我們不知道什麼'消息'是 – 2014-10-31 18:25:23
道歉。在ChatHistory上調用create()時會觸發該錯誤。消息是表示套接字消息的簡單類。 – 2014-10-31 19:13:36
您是否像https://laracasts.com/forum/?p=969-codeception-and-laravel/0中描述的那樣嘗試啓動Laravel? – 2014-11-03 21:46:03