2013-11-23 31 views
1

我正在使用AngularJS ng-resource,但我遇到了一個數組混淆的問題。我的NG-資源是這樣AngularJS將對象作爲數組發送給PHP

app.factory('MyModel', ['$resource', 'api_domain', 
function($resource, api_domain) { 

     return $resource(api_domain + 'adsizes/:id', { 
      id : '@id' 
     }, { 
      get : {method: 'GET', isArray: true } 
     }) 

}]); 

我的控制器看起來像這樣:

app.controller("MyCtrl", ['$scope', 'MyModel', 
    function($scope, MyModel) { 

     MyModel.get({ 
        id : id, 
        'conditions': { 'join' : 'table2'} 
       }, function() { 

       }); 
}); 

的問題是逝者如斯條件,使:

conditions:{"join":"table2"} 

哪個傳遞到PHP作爲一個必須被解碼的字符串。我的問題是我如何傳遞條件作爲php關聯數組?

+0

難道你不只是用於該json_encode在PHP中,你可以不發比用GET或POST請求反正弦其他的什麼嗎? – adeneo

+0

json_encode會使它成爲json字符串。 –

+0

它會,我當然意味着json_decode,將字符串轉換爲對象或數組。 – adeneo

回答

1

附加給你的GET請求和VAR轉儲$ _GET。

?條件[加入] =表2

0

你的參數需要是一個數組,而不是一個對象:

... 
conditions: ['join', 'table2'] 
... 
+0

不完全。參數正在通過$ GET傳遞,所以不需要php://輸入 –

+0

我之所以不這樣做PHP是因爲我不想改變我所有的php來適應這個變化 –

+0

In在這種情況下,您需要使用數組而不是對象作爲輸入。我會相應地更新我的答案。 –