restコントローラーではbefore内で、全体のログインチェックを行う事が出来ない。
class Controller_Api extends \Fuel\Core\Controller_Rest
{
public function get_create()
{
$name = Input::get('key');
$this->data['content'] = array('key' => $name);
return $this->response($this->data, 200);
}
public function auth()
{
if(Auth::check())
{
return true;
}
return false;
}
}
config内でauthにrestコントローラーで認証を行わせるメソッドを記述する.
'auth' => 'auth',
http://xxx.com/api/create.json?key=hoge
ログインしていない場合
{"status":0,"error":"Not Authorized"}
ログインしている場合
{"content":{"key":"hoge"}}