Last active
January 1, 2016 03:09
-
-
Save masayuki5160/8083479 to your computer and use it in GitHub Desktop.
どっかからもってきたFuelPHPでAPIをつくるソース。Restというコントローラーがあるのでそれを継承してやるだけ。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hoge.com/testapi/name.json ➡ JSONでかえってくる
hoge.com/testapi/name.xml ➡ XMLでかえってくる