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

  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="qwawimqqmiuu" 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="qwawimqqmiuu" 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="qwawimqqmiuu" 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>
                        • 主站蜘蛛池模板: 一区二区在线不卡 | 精品综合久久久 | 日韩精品一区二区三区中文在线 | 在线观看黄免费 | 精品久久久久久国产 | 韩国久久 | 精品91视频| 日操操| 精品一二区 | 美女视频一区二区三区 | 亚洲一区二区在线播放 | 免费视频成人国产精品网站 | 黄色在线免费看 | 日韩高清成人 | 中文字幕av网址 | 91.色 | 亚洲视频免费在线观看 | 色婷婷狠狠 | av播播| 亚洲综合大片69999 | 久久精品久久久久久 | 久久久久国产一区二区三区四区 | 91美女视频 | 欧美一区视频 | 日本一区二区高清不卡 | 黑人精品欧美一区二区蜜桃 | 做a视频在线观看 | 国产高清精品一区二区三区 | 国产精品视频一区二区三区四区国 | 在线观看视频一区二区三区 | 999re5这里只有精品 | 亚洲婷婷六月天 | 日本在线播放 | 一二三四在线视频观看社区 | 日韩av在线一区二区 | 国产亚洲一区二区三区在线 | 国产午夜av片 | 高清黄色毛片 | 久久久久久久久国产精品 | 男女羞羞网站 | 亚洲第一av |