Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Rest Controller and Auth
  • In the documentation (http://fuelphp.com/docs/general/controllers/rest.html) I found the REST controller config "auth". 

    I added a custom method "has_access" to it, where I just do the following:

    public function has_access() {
    return \Auth::check();
    }

    But it doesn't work, even if I am logged in, since the REST controller checks if the result of the method is an instance of \Response. 

    Is this an error in the documentation:  "This method may return a boolean (true will allow the request, false will return a default 401 response is returned), or a Response object. "?


  • HarroHarro
    Accepted Answer
    Which version of Fuel are you on? This was introduced in 1.6.1, older versions didn't allow a Response at all.

    The current Controller_Rest does:

            elseif (method_exists($this, $this->auth))
            {
                if (($valid_login = $this->{$this->auth}()) instanceOf \Response)
                {
                    return $valid_login;
                }
            }

    which means if $this->auth contains "has_access", and $this->has_access() exists, it will be called here, and the result will be stored in $valid_login. If a Response is returned, it is returned right away, if not it falls through.

    So the documentation matches the functionality in the code.
  • Ah. My version of code looks like this:

    if ($valid_login = $this->{$this->auth}() instanceOf \Response)

    I looked now into github and found out, that this error was fixed already in commit a670832d8f88acb9160f42ca9c45c5a3b36b69a6

    Sorry for that. 

Howdy, Stranger!

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

In this Discussion