pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="g6kai22" 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:致命錯(cuò)誤:在非對象上調(diào)用成員函數(shù)

        Laravel/Eloquent: Fatal error: Call to a member function connection() on a non-object(Laravel/Eloquent:致命錯(cuò)誤:在非對象上調(diào)用成員函數(shù) 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="mgs0e2q" id='0oZni'><tfoot id='0oZni'></tfoot><dl id='0oZni'><fieldset id='0oZni'></fieldset></dl></div>
                  本文介紹了Laravel/Eloquent:致命錯(cuò)誤:在非對象上調(diào)用成員函數(shù) connection()的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在 Laravel 4 中構(gòu)建一個(gè)包,但在嘗試訪問似乎是正確實(shí)例化對象的數(shù)據(jù)庫時(shí)出現(xiàn)非對象錯(cuò)誤.設(shè)置如下:

                  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(),
                                ));
                  

                  錯(cuò)誤:

                  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!

                  這是實(shí)例化 ChatHistory 并調(diào)用寫入的類:

                  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 不可用的事實(shí)表明 Eloquent 沒有被加載到頂部?

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

                  推薦答案

                  答案:

                  在您的服務(wù)提供商的 boot 方法中引導(dǎo)您的包.

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

                  說明:

                  既然你正在開發(fā)一個(gè)與 Laravel 一起使用的包,那么制作你自己的 Capsule 實(shí)例是沒有意義的.你可以直接使用 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 在您的代碼命中時(shí)尚未設(shè)置.

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

                  您沒有向我們展示您的服務(wù)提供商,但我猜您正在使用一個(gè)并在 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.

                  由于您的包依賴于不同的服務(wù)提供商 (DatabaseServiceProvider) 在它自己執(zhí)行之前進(jìn)行連接,因此引導(dǎo)包的正確位置是您的服務(wù)提供商的 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 方法在服務(wù)提供者注冊后立即調(diào)用,而 boot 命令僅在請求被路由之前調(diào)用.

                  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.

                  因此,如果您的服務(wù)提供者中的操作依賴于已經(jīng)注冊的另一個(gè)服務(wù)提供者 [...],您應(yīng)該使用 boot 方法.

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

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

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

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)
                    <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="2a2saey" id='aK4cT'><tfoot id='aK4cT'></tfoot><dl id='aK4cT'><fieldset id='aK4cT'></fieldset></dl></div>

                          • <bdo id='aK4cT'></bdo><ul id='aK4cT'></ul>
                            主站蜘蛛池模板: 面粉仓_储酒罐_不锈钢储酒罐厂家-泰安鑫佳机械制造有限公司 | 水上浮桥-游艇码头-浮动码头-游船码头-码瑞纳游艇码头工程 | 爆炸冲击传感器-无线遥测传感器-航天星百科 | 吸音板,隔音板,吸音材料,吸音板价格,声学材料 - 佛山诺声吸音板厂家 | 电渗析,废酸回收,双极膜-山东天维膜技术有限公司 | 无线遥控更衣吊篮_IC卡更衣吊篮_电动更衣吊篮配件_煤矿更衣吊篮-力得电子 | 飞扬动力官网-广告公司管理软件,广告公司管理系统,喷绘写真条幅制作管理软件,广告公司ERP系统 | 南京办公用品网-办公文具用品批发-打印机耗材采购 | 尾轮组_头轮组_矿用刮板_厢式刮板机_铸石刮板机厂家-双驰机械 | 培训一点通 - 合肥驾校 - 合肥新亚驾校 - 合肥八一驾校 | 作文导航网_作文之家_满分作文_优秀作文_作文大全_作文素材_最新作文分享发布平台 | 华中线缆有限公司-电缆厂|电缆厂家|电线电缆厂家 | 防火门|抗爆门|超大门|医疗门|隔声门-上海加汇门业生产厂家 | 广域铭岛Geega(际嘉)工业互联网平台-以数字科技引领行业跃迁 | 昊宇水工|河北昊宇水工机械工程有限公司 | 成都思迪机电技术研究所-四川成都思迪编码器 | 别墅图纸超市|别墅设计图纸|农村房屋设计图|农村自建房|别墅设计图纸及效果图大全 | 热处理温控箱,热处理控制箱厂家-吴江市兴达电热设备厂 | 电动葫芦-河北悍象起重机械有限公司| 阳光1号桔柚_无核沃柑_柑橘新品种枝条苗木批发 - 苧金网 | 精密线材测试仪-电线电缆检测仪-苏州欣硕电子科技有限公司 | 日本SMC气缸接头-速度控制阀-日本三菱伺服电机-苏州禾力自动化科技有限公司 | 东莞市海宝机械有限公司-不锈钢分选机-硅胶橡胶-生活垃圾-涡电流-静电-金属-矿石分选机 | TwistDx恒温扩增-RAA等温-Jackson抗体-默瑞(上海)生物科技有限公司 | 变压器配件,变压器吸湿器,武强县吉口变压器配件有限公司 | 欧盟ce检测认证_reach检测报告_第三方检测中心-深圳市威腾检验技术有限公司 | 液压压力机,液压折弯机,液压剪板机,模锻液压机-鲁南新力机床有限公司 | ASA膜,ASA共挤料,篷布色母料-青岛未来化学有限公司 | pbt头梳丝_牙刷丝_尼龙毛刷丝_PP塑料纤维合成毛丝定制厂_广州明旺 | 超声骨密度仪,双能X射线骨密度仪【起草单位】,骨密度检测仪厂家 - 品源医疗(江苏)有限公司 | 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 砂石生产线_石料生产线设备_制砂生产线设备价格_生产厂家-河南中誉鼎力智能装备有限公司 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | 铝单板_铝窗花_铝单板厂家_氟碳包柱铝单板批发价格-佛山科阳金属 | 旗帜网络笔记-免费领取《旗帜网络笔记》电子书 | 强效碱性清洗剂-实验室中性清洗剂-食品级高纯氮气发生器-上海润榕科学器材有限公司 | 微量水分测定仪_厂家_卡尔费休微量水分测定仪-淄博库仑 | 三氯异氰尿酸-二氯-三氯-二氯异氰尿酸钠-优氯净-强氯精-消毒片-济南中北_优氯净厂家 | 软瓷_柔性面砖_软瓷砖_柔性石材_MCM软瓷厂家_湖北博悦佳软瓷 | 陕西自考报名_陕西自学考试网 | 微信小程序定制,广州app公众号商城网站开发公司-广东锋火 |