Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Rest Controller $this->response not returning anything - v1.3
  • Using 1.2 I could return a value from a rest controller by using
    $this->response($array);
    
    Now using that or even putting "return" in front of that doesn't seem to get a response. The docs still show that using that is correct, but maybe they're outdated?
    I know that "$this-response" has a value because I can print_r it and see the value but when trying to retrieve the value either through a url or an app I get nothing. Any idea why this would be happening? Is $this->response deprecated?
  • Nothing has changed to the REST controller in quite some time. Do you perhaps have an after() method in your controller that is not correct (i.e. doesn't take the response as a parameter and/or doesn't return the response)?
  • I don't have an after() method. Right now it's a very simple class with one method, just for testing. The class extends a base class which extends Controller_Rest. The only method that the base class has is a before() method which does call parent::before(). I can't, for the life of me figure out what is causing the problem since this worked well with v1.2.
  • Any error messages? Any logs? I can't find any reason why it shouldn't work. Lots of people, including myself, use it on a daily basis. btw, you don't need to use $this->response, your action can just return the array. The REST controllers after() method will take care of the conversion.
  • Unfortunately there are no error messages or logs; just a white screen of death. To simplify things in my controller I quit extending my base controller and just started extending the rest controller. I just wanted to weed out any errors that might have been in my base controller. Here is what my controller looks like now:
    class Controller_Get extends Controller_Rest
    {
     public function get_user()
     {
      $user = DB::select('email')
       ->from('users')
       ->where('id', '=', Input::get('id'))
       ->execute()->as_array();
    
                    //Here I can print_r($user) and get the results I'm looking for 
                    //so I now it's routing correctly and I'm getting results
    
      //$this->response($user);
      return $user;
     }
    }
    
    Then I browse over to http://mydomain.com/get/user.xml?id=1 This is a fresh install of 1.3 with just the necessary config settings adjusted. Nothing is out of the ordinary. I'm hoping that this is just a stupid mistake on my part but I've spent hours trying to fix it myself.
  • You can not browse to it. The Controller_Rest expects an ajax call. If you want to see the result in the browser you will have to fake that.
  • Hmm. That's odd. I've done 3 other api's using Fuel 1.2 and have been able to browse to them and get the info I wanted in the format I wanted. But I've decided that it is something on my part, though for the life of me I can't figure out what it is. But I just installed 1.3 on another site and it works just fine. I wish I knew what caused the problem so I can avoid it in the future. Thanks for your help Harro!

Howdy, Stranger!

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

In this Discussion