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

  1. <tfoot id='c9DdR'></tfoot>
  2. <small id='c9DdR'></small><noframes id='c9DdR'>

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

      如何通過 Slim php 和 Paris 將主干模型數據發布到數

      How to POST backbone model data to DB through Slim php and Paris(如何通過 Slim php 和 Paris 將主干模型數據發布到數據庫)

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

        • <legend id='1YzLt'><style id='1YzLt'><dir id='1YzLt'><q id='1YzLt'></q></dir></style></legend>
        • <tfoot id='1YzLt'></tfoot>
            <tbody id='1YzLt'></tbody>
            <bdo id='1YzLt'></bdo><ul id='1YzLt'></ul>

              <small id='1YzLt'></small><noframes id='1YzLt'>

                本文介紹了如何通過 Slim php 和 Paris 將主干模型數據發布到數據庫的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我試圖了解 Backbone.js、Slim PHP 和 Paris/Idiorm 可能會一起工作,但我無法完成流程,從模型屬性數據開始,一直到數據庫.問題:當我執行 model.save() 時,到底什么會被發送到我的服務器?

                I'm trying to get an understanding of how Backbone.js, Slim PHP and Paris/Idiorm might work together and I'm having trouble completing the flow, starting with model attribute data, all the way to the database. PROBLEM: What exactly gets sent to my server when I do model.save() ?

                客戶端:Backbone.js

                Client-side: Backbone.js

                var Donut = Backbone.Model.extend({
                    defaults: {
                        name: null,
                        sparkles: false,
                        creamFilled: false
                    },
                    url: function() {
                        return '/donut';
                    }
                });
                
                var bostonCream = new Donut({
                    name: 'Bawston Cream',
                    sparkles: true,
                    creamFilled: true
                });
                
                bostonCreme.save();  // <-- Problem: Not sure what & format this is sending
                

                我認為以上是我的主要問題.我的理解是,骨干默認情況下會知道發送 POST 數據,因為它是新的.它將它發送到路由的/donut,但我的問題是它發送了什么?以什么格式?我想要的結果是將這些甜甜圈屬性保存到我的數據庫中.我可以使用 jQuery $.post()...

                I think the above is my main problem. My understanding is that backbone will by default, know to send POST data since it's new. It sends it to /donut which is routed, but the question I have is WHAT does it send? And in what format? The outcome I want is to save those donut attributes to my DB. I can pass this server-side code a json like this using jQuery $.post()...

                var myDonut = {"name":"Jelly Filled", "sparkles":false, "creamFilled":true};
                $.post('http://localhost/donut', myDonut);
                

                ...它高興地接受了它,將它保存到我的數據庫中.但是在當前設置嘗試發送我的主干甜甜圈數據時,我收到 POST 500 內部服務器錯誤.下面我有一些服務器端代碼.

                ...and it happily takes it, saves it to my database. But with the current setup trying to send my backbone donut data, I get POST 500 Internal Server Error. Below I have some server-side code.

                服務器端:Slim PHP w/Paris

                Server-side: Slim PHP w/ Paris

                class Donut extends Model {}
                
                $app->post('/donut', function() use ($app) {  // Slim framework routes my POST...
                
                    $donuts = Model::factory('Donut')->create();  // Paris stuff...
                
                    $donuts->name = $app->request()->post('name');  // Slim request parameters...
                    $donuts->sparkles = $app->request()->post('sparkles');
                    $donuts->creamFilled = $app->request()->post('creamFilled');
                
                    $donuts->save();   // Paris... Save name, sparkles, and creamFilled to my DB
                });
                

                我感覺答案就在那里,但我看過的每個例子似乎都遺漏了一個或另一個拼圖,我無法理解啊哈!"片刻.如果這是一個非常無知的問題,我提前感謝您并道歉.:-P

                I have a feeling the answer is out there, but every example I've looked at seems to be missing one piece of the puzzle or another and I can't get that "A-hA!" moment. I thank you in advance and apologize if this is a really ignorant question. :-P

                跟進/1

                你能粘貼錯誤信息嗎?

                我在當前收到一個 POST http://localhost:8888/donut 500(內部服務器錯誤)狀態.我可以通過以下代碼獲取更多信息.

                I get a POST http://localhost:8888/donut 500 (Internal Server Error) in the current state. I can get more information with the following code.

                bostonCream.save({}, {  // REPLACE bostonCream.save();
                    success: function(model, response) {
                        console.log('SUCCESS:');
                        console.log(response);
                    },
                    error: function(model, response) {
                        console.log('FAIL:');
                        console.log(response);
                    }
                });
                

                現在,當我運行主干的 save() 時,我仍然收到 500 錯誤,但還有 XMLHttpRequest 作為我的 FAIL 響應.來自 XMLHttpRequest 的唯一顯著線索是 responseText = SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null.

                Now when I run backbone's save(), I still get the 500 Error but also XMLHttpRequest as my FAIL response. The only remarkable clue from the XMLHttpRequest is responseText = SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null.

                所以我的猜測是 1) 我在使用 save() 搞砸了一些東西,因為它沒有正確捕獲我的屬性,2) 它當前正在以我的服務器沒有的格式發送我的屬性使用標準的 $app->request()->post() Slim 方法識別(當我嘗試直接使用 $_POST 訪問時似乎也沒有做太多事情),3)我的服務器沒有正確設置來接受這種方法正在發送的數據.

                So my guess is that either 1) I'm messing something up with the save() in that it isn't capturing my attributes correctly, 2) It is currently sending my attributes in a format that my server isn't recognizing with the standard $app->request()->post() Slim methods (Doesn't seem to do much when I try accessing directly with $_POST either), 3) My server isn't setup correctly to take the kind of data that is being sent.

                我注意到的另一件事是,當我添加時

                Another thing I noticed although I don't know what to make of it is that when I add

                echo $_POST;
                

                它返回給我一個空數組.仍然給我 FAIL.但是,如果我這樣做...

                It returns to me an empty array. Still gives me the FAIL. If I do THIS however...

                echo json_encode($_POST);
                

                它給了我一個 SUCCESS 并且響應是 [ ].里面什么都沒有.顯然,我的 POST 數據仍然不穩定.

                It gives me a SUCCESS and the response is a [ ]. Nothing in there. Clearly my POST data is still wonky.

                推薦答案

                我想出了一個解決方案來完成這個問題:如何使用默認的主干 save() 和 .sync 從客戶端獲取數據到服務器 - 傳遞給Slim php 框架并通過 Paris/Idiorm 進入我的數據庫.

                I came up with a solution to completing the problem: how to get data from client to server using the default backbone save() and .sync - passed over to the Slim php framework and going through Paris/Idiorm to my DB.

                我在下面包含了我的工作更新代碼:

                I am including my working updated code below:

                客戶端:Backbone.js

                var Donut = Backbone.Model.extend({
                    defaults: {
                        name: null,
                        sparkles: false,
                        creamFilled: false
                    },
                    url: function() {
                        return '/donut';
                    }
                });
                
                var bostonCream = new Donut({
                    name: 'Bawston Cream',
                    sparkles: true,
                    creamFilled: true
                });
                
                bostonCream.save();
                
                /***** If you want to check out the response to save() ? ***
                bostonCream.save({}, {
                    success: function(model, response) {
                        console.log('SUCCESS:');
                        console.log(response);
                    },
                    error: function(model, response) {
                        console.log('FAIL:');
                        console.log(response);
                    }
                });
                ************************************************************/
                

                服務器端:Slim PHP w/Paris/Idorm

                class Donut extends Model {}
                
                $app->post('/donut', function() use ($app) {
                
                    $donuts = Model::factory('Donut')->create();
                
                    /* EDIT: Works... but not the Slim way
                    $parameters = json_decode(file_get_contents('php://input'), true);
                    $donuts->name = $parameters['name'];
                    $donuts->sparkles = $parameters['sparkles'];
                    $donuts->creamFilled = $parameters['creamFilled']; */
                
                    /* SLIM: Using Slim Request Object */
                    $requestBody = $app->request()->getBody();  // <- getBody() of http request
                    $json_a = json_decode($requestBody, true);
                    $donuts->name = $json_a['name'];
                    $donuts->sparkles = $json_a['sparkles'];
                    $donuts->creamFilled = $json_a['creamFilled'];
                
                    $donuts->save();
                
                    // echo json_encode($parameters); // Prove you've captured POST data, send it back
                }
                

                現在我的代碼很高興地使用 Backbone.js 的默認設置(沒有更改同步)并將正確的模型屬性信息發送到我的服務器,這似乎成功地接受了數據并將其保存到我的數據庫中.

                Now my code is happily using the default settings of Backbone.js (no changes to sync) and sending proper model attribute information to my server which seems to be successfully accepting the data and saving it to my DB.

                這里的關鍵似乎是這一行...

                The key here seems to be this line...

                /* $parameters = json_decode(file_get_contents('php://input'), true); */
                // EDITED: getBody() method not documented in Develop Doc, only Stable @ time of post
                
                $requestBody = $app->request()->getBody();
                

                這篇關于如何通過 Slim php 和 Paris 將主干模型數據發布到數據庫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)
                  <tbody id='5lyiO'></tbody>

                  1. <i id='5lyiO'><tr id='5lyiO'><dt id='5lyiO'><q id='5lyiO'><span id='5lyiO'><b id='5lyiO'><form id='5lyiO'><ins id='5lyiO'></ins><ul id='5lyiO'></ul><sub id='5lyiO'></sub></form><legend id='5lyiO'></legend><bdo id='5lyiO'><pre id='5lyiO'><center id='5lyiO'></center></pre></bdo></b><th id='5lyiO'></th></span></q></dt></tr></i><div class="vbbtljv" id='5lyiO'><tfoot id='5lyiO'></tfoot><dl id='5lyiO'><fieldset id='5lyiO'></fieldset></dl></div>
                    <tfoot id='5lyiO'></tfoot>
                  2. <small id='5lyiO'></small><noframes id='5lyiO'>

                      <legend id='5lyiO'><style id='5lyiO'><dir id='5lyiO'><q id='5lyiO'></q></dir></style></legend>
                        <bdo id='5lyiO'></bdo><ul id='5lyiO'></ul>
                        • 主站蜘蛛池模板: 包头市鑫枫装饰有限公司| 金刚网,金刚网窗纱,不锈钢网,金刚网厂家- 河北萨邦丝网制品有限公司 | SF6环境监测系统-接地环流在线监测装置-瑟恩实业 | 首页_中夏易经起名网| 衬四氟_衬氟储罐_四氟储罐-无锡市氟瑞特防腐科技有限公司 | 纸张环压仪-纸张平滑度仪-杭州纸邦自动化技术有限公司 | 基本型顶空进样器-全自动热脱附解吸仪价格-AutoHS全模式-成都科林分析技术有限公司 | 网站优化公司_SEO优化_北京关键词百度快速排名-智恒博网络 | 整车VOC采样环境舱-甲醛VOC预处理舱-多舱法VOC检测环境仓-上海科绿特科技仪器有限公司 | 离子色谱自动进样器-青岛艾力析实验科技有限公司 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | 废旧物资回收公司_广州废旧设备回收_报废设备物资回收-益美工厂设备回收公司 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 淄博不锈钢,淄博不锈钢管,淄博不锈钢板-山东振远合金科技有限公司 | 东莞工作服_东莞工作服定制_工衣订做_东莞厂服 | 不锈钢轴流风机,不锈钢电机-许昌光维防爆电机有限公司(原许昌光维特种电机技术有限公司) | 东莞压铸厂_精密压铸_锌合金压铸_铝合金压铸_压铸件加工_东莞祥宇金属制品 | 茶叶百科网-茶叶知识与茶文化探讨分享平台 | 上海办公室装修公司_办公室设计_直营办公装修-羚志悦装 | 今日娱乐圈——影视剧集_八卦娱乐_明星八卦_最新娱乐八卦新闻 | 地磅-地秤-江阴/无锡地磅-江阴天亿计量设备有限公司_ | Magnescale探规,Magnescale磁栅尺,Magnescale传感器,Magnescale测厚仪,Mitutoyo光栅尺,笔式位移传感器-苏州连达精密量仪有限公司 | 阳光模拟试验箱_高低温试验箱_高低温冲击试验箱_快速温变试验箱|东莞市赛思检测设备有限公司 | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | 济南电缆桥架|山东桥架-济南航丰实业有限公司 | 透平油真空滤油机-变压器油板框滤油机-滤油车-华之源过滤设备 | 工业车间焊接-整体|集中除尘设备-激光|等离子切割机配套除尘-粉尘烟尘净化治理厂家-山东美蓝环保科技有限公司 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 广州/东莞小字符喷码机-热转印打码机-喷码机厂家-广州瑞润科技 | 东莞市踏板石餐饮管理有限公司_正宗桂林米粉_正宗桂林米粉加盟_桂林米粉加盟费-东莞市棒子桂林米粉 | 变色龙云 - 打包app_原生app_在线制作平台_短链接_ip查询 | 仿古瓦,仿古金属瓦,铝瓦,铜瓦,铝合金瓦-西安东申景观艺术工程有限公司 | 四合院设计_四合院装修_四合院会所设计-四合院古建设计与建造中心1 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | 河南彩印编织袋,郑州饲料编织袋定制,肥料编织袋加工厂-盛军塑业 河南凯邦机械制造有限公司 | 涿州网站建设_网站设计_网站制作_做网站_固安良言多米网络公司 | 护腰带生产厂家_磁石_医用_热压护腰_登山护膝_背姿矫正带_保健护具_医疗护具-衡水港盛 | 山东臭氧发生器,臭氧发生器厂家-山东瑞华环保设备 | 天津次氯酸钠酸钙溶液-天津氢氧化钠厂家-天津市辅仁化工有限公司 | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 |