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>
                        • 主站蜘蛛池模板: 加气混凝土砌块设备,轻质砖设备,蒸养砖设备,新型墙体设备-河南省杜甫机械制造有限公司 | 北京开业庆典策划-年会活动策划公司-舞龙舞狮团大鼓表演-北京盛乾龙狮鼓乐礼仪庆典策划公司 | 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 安全光栅|射频导纳物位开关|音叉料位计|雷达液位计|两级跑偏开关|双向拉绳开关-山东卓信机械有限公司 | 皮带式输送机械|链板式输送机|不锈钢输送机|网带输送机械设备——青岛鸿儒机械有限公司 | 政府回应:200块在义乌小巷能买到爱情吗?——揭秘打工族省钱约会的生存智慧 | 数控走心机-走心机价格-双主轴走心机-宝宇百科 | 上海盐水喷雾试验机_两厢式冷热冲击试验箱-巨怡环试 | ph计,实验室ph计,台式ph计,实验室酸度计,台式酸度计 | 实验室pH计|电导率仪|溶解氧测定仪|离子浓度计|多参数水质分析仪|pH电极-上海般特仪器有限公司 | 振动台-振动试验台-振动冲击台-广东剑乔试验设备有限公司 | 深圳宣传片制作_产品视频制作_深圳3D动画制作公司_深圳短视频拍摄-深圳市西典映画传媒有限公司 | 隔离变压器-伺服变压器--输入输出电抗器-深圳市德而沃电气有限公司 | ?水马注水围挡_塑料注水围挡_防撞桶-常州瑞轩水马注水围挡有限公司 | 专注提供国外机电设备及配件-工业控制领域一站式服务商-深圳市华联欧国际贸易有限公司 | 鼓风干燥箱_真空烘箱_高温干燥箱_恒温培养箱-上海笃特科学仪器 | 跨境物流_美国卡派_中大件运输_尾程派送_海外仓一件代发 - 广州环至美供应链平台 | 悬浮拼装地板_篮球场木地板翻新_运动木地板价格-上海越禾运动地板厂家 | 北京印刷厂_北京印刷_北京印刷公司_北京印刷厂家_北京东爵盛世印刷有限公司 | 电力电子产业网 | POM塑料_PBT材料「进口」聚甲醛POM杜邦原料、加纤PBT塑料报价格找利隆塑料 | 转子泵_凸轮泵_凸轮转子泵厂家-青岛罗德通用机械设备有限公司 | 化工ERP软件_化工新材料ERP系统_化工新材料MES软件_MES系统-广东顺景软件科技有限公司 | EPK超声波测厚仪,德国EPK测厚仪维修-上海树信仪器仪表有限公司 | 烟台游艇培训,威海游艇培训-烟台市邮轮游艇行业协会 | 山东锐智科电检测仪器有限公司_超声波测厚仪,涂层测厚仪,里氏硬度计,电火花检漏仪,地下管线探测仪 | 北京公司注册_代理记账_代办商标注册工商执照-企力宝 | ICP备案查询_APP备案查询_小程序备案查询 - 备案巴巴 | 客服外包专业服务商_客服外包中心_网萌科技 | 水冷散热器_水冷电子散热器_大功率散热器_水冷板散热器厂家-河源市恒光辉散热器有限公司 | 成都租车_成都租车公司_成都租车网_众行宝 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | 网站建设_网站制作_SEO优化推广_百度推广开户_朋友圈网络科技 | 东莞动力锂电池保护板_BMS智能软件保护板_锂电池主动均衡保护板-东莞市倡芯电子科技有限公司 | TPE_TPE热塑性弹性体_TPE原料价格_TPE材料厂家-惠州市中塑王塑胶制品公司- 中塑王塑胶制品有限公司 | 苏商学院官网 - 江苏地区唯一一家企业家自办的前瞻型、实操型商学院 | 蒜肠网-动漫,二次元,COSPLAY,漫展以及收藏型模型,手办,玩具的新媒体.(原变形金刚变迷TF圈) | 武汉高温老化房,恒温恒湿试验箱,冷热冲击试验箱-武汉安德信检测设备有限公司 | 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰 | 采暖炉_取暖炉_生物质颗粒锅炉_颗粒壁炉_厂家加盟批发_烟台蓝澳采暖设备有限公司 | 全自动包装秤_全自动上袋机_全自动套袋机_高位码垛机_全自动包装码垛系统生产线-三维汉界机器(山东)股份有限公司 |