Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Rest controller issue
  • Hey, So I'm trying to get this to at least grab the $id from the url and it just throws out an error.
    heres the url i put in and the error: [url=http://localhost:8888/projects/1]http://localhost:8888/projects/1[/url]
    ErrorException [ Warning ]: Missing argument 1 for Controller_Projects::get_projectbyid() my rest function:
    public function get_projectbyid($id) 
        {
                $projects = Model_Projects::find($id);
                $this->response($projects);
        }
    

    my route:
    'projects/(:any)' => 'projects/projectbyid/$1',
    

    Any idea why this isn't working? Am I doing something wrong?
  • Use Input::get() instead as all params need to be in a key/value pair. Pretty URL's have no place in a restful API, especially not for parameters.
  • That can't be right can it? Single quotes works fine elsewhere.
  • I couldn't get it working like this either, possibly it's a bug or not implemented (as it's one of the router examples). However doing it the way given in the REST example it does work (but just not such a friendly url). Make sure you extend Controller_Rest as well btw.
    public function get_projectbyid() 
    {
        $projects = Model_Projects::find(Input::get('id'));
        $this->response($projects);
    }
    

    With a URLs like this (no router entries) /projects/projectbyid?id=1
    /projects/projectbyid.json?id=1
  • If the routing works anything like CodeIgniter, I think you would need to wrap the value of your routing array in double quotes instead of single quotes so the "$1" will be parsed properly.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion