久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='TUJ81'><tr id='TUJ81'><dt id='TUJ81'><q id='TUJ81'><span id='TUJ81'><b id='TUJ81'><form id='TUJ81'><ins id='TUJ81'></ins><ul id='TUJ81'></ul><sub id='TUJ81'></sub></form><legend id='TUJ81'></legend><bdo id='TUJ81'><pre id='TUJ81'><center id='TUJ81'></center></pre></bdo></b><th id='TUJ81'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TUJ81'><tfoot id='TUJ81'></tfoot><dl id='TUJ81'><fieldset id='TUJ81'></fieldset></dl></div>

<small id='TUJ81'></small><noframes id='TUJ81'>

  • <legend id='TUJ81'><style id='TUJ81'><dir id='TUJ81'><q id='TUJ81'></q></dir></style></legend>

      1. <tfoot id='TUJ81'></tfoot>

          <bdo id='TUJ81'></bdo><ul id='TUJ81'></ul>

        Laravel/Eloquent:致命錯誤:在非對象上調用成員函數

        Laravel/Eloquent: Fatal error: Call to a member function connection() on a non-object(Laravel/Eloquent:致命錯誤:在非對象上調用成員函數 connection())

          <bdo id='0oZni'></bdo><ul id='0oZni'></ul>

                    <tbody id='0oZni'></tbody>
                  <legend id='0oZni'><style id='0oZni'><dir id='0oZni'><q id='0oZni'></q></dir></style></legend>

                  <small id='0oZni'></small><noframes id='0oZni'>

                  <tfoot id='0oZni'></tfoot>
                1. <i id='0oZni'><tr id='0oZni'><dt id='0oZni'><q id='0oZni'><span id='0oZni'><b id='0oZni'><form id='0oZni'><ins id='0oZni'></ins><ul id='0oZni'></ul><sub id='0oZni'></sub></form><legend id='0oZni'></legend><bdo id='0oZni'><pre id='0oZni'><center id='0oZni'></center></pre></bdo></b><th id='0oZni'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0oZni'><tfoot id='0oZni'></tfoot><dl id='0oZni'><fieldset id='0oZni'></fieldset></dl></div>
                  本文介紹了Laravel/Eloquent:致命錯誤:在非對象上調用成員函數 connection()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在 Laravel 4 中構建一個包,但在嘗試訪問似乎是正確實例化對象的數據庫時出現非對象錯誤.設置如下:

                  I'm building a package in Laravel 4 but am getting a non-object error when attempting to access the db from which seems to be a properly instantiated object. Here's the setup:

                  有問題的配置和類:

                  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"
                          }  
                      }
                  ...
                  

                  班級:

                  namespace VendorChat;
                  
                  use IlluminateDatabaseEloquentModel as Eloquent;
                  
                  
                  class ChatHistory extends Eloquent
                  {
                      protected $table = 'chat_history';
                  
                      protected $fillable = array('message', 'user_id', 'room_token');
                  
                      public function __construct($attributes = array())
                      {
                          parent::__construct($attributes);
                      }
                  
                  }
                  

                  電話:

                  $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
                  

                  我相信我遺漏了一些基本的東西.感謝您的任何幫助!

                  I believe I'm missing something fundamental and under my nose. Thanks for any and all help!

                  這是實例化 ChatHistory 并調用寫入的類:

                  Here is the class that's instantiating ChatHistory and calling the write:

                  namespace VendorChat;
                  
                  use RatchetMessageComponentInterface;
                  use RatchetConnectionInterface;
                  
                  use VendorChatClient;
                  use VendorChatMessage;
                  use VendorChatChatHistory;
                  
                  use IlluminateDatabaseModel;
                  
                  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 不可用的事實表明 Eloquent 沒有被加載到頂部?

                  The fact that DB isn't available suggest that Eloquent isn't being loaded up top?

                  推薦答案

                  答案:

                  在您的服務提供商的 boot 方法中引導您的包.

                  Bootstrap your package in your service provider's boot method.

                  說明:

                  既然你正在開發一個與 Laravel 一起使用的包,那么制作你自己的 Capsule 實例是沒有意義的.你可以直接使用 Eloquent.

                  Since you're developing a package to be used with Laravel, there's no point in making your own Capsule instance. You can just use Eloquent directly.

                  您的問題似乎源于 DB/Eloquent 在您的代碼命中時尚未設置.

                  Your problem seems to stem from DB/Eloquent not being set up yet by the time your code hits it.

                  您沒有向我們展示您的服務提供商,但我猜您正在使用一個并在 register 方法中完成所有操作.

                  You have not shown us your service provider, but I'm guessing you're using one and doing it all in the register method.

                  由于您的包依賴于不同的服務提供商 (DatabaseServiceProvider) 在它自己執行之前進行連接,因此引導包的正確位置是您的服務提供商的 boot方法.

                  Since your package depends on a different service provider (DatabaseServiceProvider) to be wired up prior to its own execution, the correct place to bootstrap your package is in your service provider's boot method.

                  這里引用了 文檔:

                  register 方法在服務提供者注冊后立即調用,而 boot 命令僅在請求被路由之前調用.

                  The register method is called immediately when the service provider is registered, while the boot command is only called right before a request is routed.

                  因此,如果您的服務提供者中的操作依賴于已經注冊的另一個服務提供者 [...],您應該使用 boot 方法.

                  So, if actions in your service provider rely on another service provider already being registered [...] you should use the boot method.

                  這篇關于Laravel/Eloquent:致命錯誤:在非對象上調用成員函數 connection()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <tfoot id='aK4cT'></tfoot><legend id='aK4cT'><style id='aK4cT'><dir id='aK4cT'><q id='aK4cT'></q></dir></style></legend>
                  1. <small id='aK4cT'></small><noframes id='aK4cT'>

                      <tbody id='aK4cT'></tbody>

                      <i id='aK4cT'><tr id='aK4cT'><dt id='aK4cT'><q id='aK4cT'><span id='aK4cT'><b id='aK4cT'><form id='aK4cT'><ins id='aK4cT'></ins><ul id='aK4cT'></ul><sub id='aK4cT'></sub></form><legend id='aK4cT'></legend><bdo id='aK4cT'><pre id='aK4cT'><center id='aK4cT'></center></pre></bdo></b><th id='aK4cT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aK4cT'><tfoot id='aK4cT'></tfoot><dl id='aK4cT'><fieldset id='aK4cT'></fieldset></dl></div>

                          • <bdo id='aK4cT'></bdo><ul id='aK4cT'></ul>
                            主站蜘蛛池模板: 午夜免费在线 | 国产免费又黄又爽又刺激蜜月al | 国产伊人久久久 | 麻豆久久久9性大片 | 日韩欧美在线观看视频 | 羞羞涩涩在线观看 | 国产精品一区二区视频 | 中文一区二区 | 亚洲美女天堂网 | 91精品国产综合久久国产大片 | 成人免费视屏 | 男人久久天堂 | 亚洲在线 | 成人黄色在线 | 国产精品日产欧美久久久久 | 99精品视频一区二区三区 | 亚洲国产一区二区三区在线观看 | 精品乱子伦一区二区三区 | 久久精品亚洲成在人线av网址 | 欧美综合在线视频 | 久草精品视频 | 欧美日韩中文字幕 | 久久免费精品 | 日韩高清一区 | 国产欧美精品一区二区三区 | 久久精品亚洲成在人线av网址 | 婷婷激情综合 | 国产精品一区一区三区 | 免费黄色日本 | 欧美一区二区视频 | av中文在线 | 午夜影院免费体验区 | 亚洲视频二区 | 欧美三级久久久 | 久久99精品久久久久久 | 成人免费观看男女羞羞视频 | 黄视频免费在线 | 精品欧美一区二区中文字幕视频 | h视频免费看 | www.日韩 | 一级黄色夫妻生活 |