Skip to content

Instantly share code, notes, and snippets.

@masayuki5160
Last active January 1, 2016 03:09
Show Gist options
  • Save masayuki5160/8083479 to your computer and use it in GitHub Desktop.
Save masayuki5160/8083479 to your computer and use it in GitHub Desktop.
どっかからもってきたFuelPHPでAPIをつくるソース。Restというコントローラーがあるのでそれを継承してやるだけ。
<?php
class Controller_Testapi extends Controller_Rest
{
//GETでリクエストがきたときはこっち
public function get_name()
{
//返したいデータを整形
$_outputBuffer = array('name' => 'test');
//$this->responseに配列として設定してやるだけでおわり
return $this->response($_outputBuffer,200);
}
//POSTでリクエストされたときはこっちが動く
public function post_name()
{
//返したいデータを整形
$_outputBuffer = array('name' => 'test');
//$this->responseに配列として設定してやるだけでおわり
return $this->response($_outputBuffer,200);
}
}
@masayuki5160
Copy link
Author

hoge.com/testapi/name.json ➡ JSONでかえってくる

hoge.com/testapi/name.xml ➡ XMLでかえってくる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment