1

I'm getting use to AngularJS ng-resource but I am having a problem serieliazing an array. My ng-resource is like this

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

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

}]);

And my controller looks like this:

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

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

                });
});

The problem is it passes the conditions like so:

conditions:{"join":"table2"}

Which passes into php as a string that has to get decoded. My question is how can I pass the conditions as associative array for php?

4
  • Wouldn't you just use json_encode for that in PHP, as you can't send anything other than strings with a GET or POST request anyway ? Commented Nov 23, 2013 at 22:59
  • json_encode would make it a json string. Commented Nov 23, 2013 at 23:01
  • It would, I of course meant json_decode, converting the string to an object or array. Commented Nov 23, 2013 at 23:06
  • I could do that, but that would require modifying the PHP to suite that javascript, something I want to avoid Commented Nov 23, 2013 at 23:20

2 Answers 2

1

Append this to your get request and var dump $_GET.

?conditions[join]=table2

Sign up to request clarification or add additional context in comments.

Comments

0

Your parameter needs to be an array, rather than an object:

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

3 Comments

Not quite. The parameters are being passed through $GET so there is no need for php://input
The reason why I'm not doing it PHP is because I do not want to have to change all my php to accomdate this one change
In that case, you need to use an array--rather than an object--as the input. I'll update my answer accordingly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.