作成日:2018-09-17, 更新日:2018-09-24
基本
class Controller_Test extends Controller_Hybrid {
// URL から /test/list をリクエストすると呼ばれる
public function action_list() {
$this->template->content = 'Hello World!';
}
// /test/list?foo=bar へ Ajax リクエストすると呼ばれる
public function get_list() {
$this->response(array(
'foo' => Input::get('foo'),
'baz' => array(
1, 50, 219
),
'empty' => null
));
}
}
メモ
上記の「get_list()」・・・HTTP メソッドをプレフィックスしたから「get_」になるっぽい。
POST送信なら「post_list()」になるっぽい。何も考えずに「action_」を使っていた。
▼下記のようにpostとgetでコントローラーを分けることが可能
public function post_list() {
$this->response(array(
'status' => 200,
));
}
public function get_list() {
$this->response(array(
'status' => 404,
));
}
※「post_list()」しか用意せずに「get」でアクセスしたら「405 (Method Not Allowed)」が返ってきた。