31
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

fuelphpのrestコントローラでログインチェックを行う

Last updated at Posted at 2014-05-02

rest controllerでのログインチェック

restコントローラーでログインチェックを行う方法

controller

以下のようなrestの例があった場合。

fuel/app/classes/api.php
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

config内でauthにrestコントローラーで認証を行わせるメソッドを記述する.

fuel/config/rest.php (fuel/core/config/rest.php)
	'auth' => 'auth',

結果

ログインしていない場合

{"status":0,"error":"Not Authorized"}

ログインしている場合

{"content":{"key":"hoge"}}
31
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?