Welcome Guest, Not a member yet? Register   Sign In
REST_Controller does not work with parameters in the function
#1

[eluser]xtcsonik[/eluser]
I have a custom route:
Code:
$route['users/(:num)/groups'] = 'groups/index/$1';
The controller looks like this:
Code:
require APPPATH.'/libraries/REST_Controller.php';

class Groups extends CI_Controller{

    public function index($user_id)
    {
            exit($user_id);
    }
}

It works fine when I'm using CI_Controller but when I switch it to REST_Controller and update the method to include the HTTP verb (index_get), I keep receiving an error:
Missing argument 1 for Groups::index_get(),

Any ideas?
#2

[eluser]Andreas Karlsson[/eluser]
I don't know how the method is constructed but it wants an argument and you are not giving it one.

I have never tried the REST_Controller but you could try something like function index_get($argument = 'default var') where you declare the method.
#3

[eluser]xtcsonik[/eluser]
Thanks for the response.

I'm starting to think its not possible to use Phil's rest server to create vanity urls. So urls like
'http://domain.com/api/users/381/friends?format=json'
are out of the question.

Instead we need to use
'http://domain.com/api/friends?user_id=381'
#4

[eluser]Andreas Karlsson[/eluser]
I got interested in this and in my googleing i found this: http://net.tutsplus.com/tutorials/php/wo...igniter-2/
Maybe it does help you, maybe not. You probably know this already Smile
#5

[eluser]xtcsonik[/eluser]
Thanks. Have it pretty much memorized but haven’t been able to figure this one out.
#6

[eluser]Phil Sturgeon[/eluser]
You could use GET variables as mentioned above and this was expected in older versions. I'm not sure when/if this made it into a tag yet, but this change was made here.

Try grabbing the latest file from GitHub to see if you can use URI segments properly there.

On the other hand it COULD be an issue with your routing. Did you try loading the URL directly instead of via the route?
#7

[eluser]xtcsonik[/eluser]
Found and resolved. I grabbed the latest and it was fixed. I was using an older download package apparently.

Thanks for the help!




Theme © iAndrew 2016 - Forum software by © MyBB