post_index(),get_index()などでルーティングできない設計の場合。
従来の方法
本来は以下のように接頭辞に
POST/GETを指定することでルーティングすることができる。
class Controller_Example extends Controller {
public function get_index() {
}
public function post_index() {
}
}
action_index()内での判定方法
同一アクション内で
POST/GETを判定したい場合は以下のように
Input::method()を使用する。
class Controller_Example extends Controller {
public function action_index() {
if( Input::method() == 'GET' ) {
}
if( Input::method() == 'POST' ) {
}
}
}
Input クラスのmethod()は HTTP メソッドを返却する。(GET, POST, DELETE なんかが取れる)
method($default = 'GET')| Static | Yes |
|---|
| Parameters |
| Param | Default | Description |
|---|
| $default | 'GET'
| Default HTTP method. |
|---|
|
|---|
| Returns | string |
|---|
| Example |
Input::method();
|
|---|
引用:
Input - Classes - FuelPHP Documentation