CakePHP3でフォームから値を受け取る方法

POSTの場合

View (index.ctp)

<form method="post" action="/hoge/index">
<input type="text" name="text_data">
<input type="submit">
</form>

Controller (hoge)

$str = $this->request->data('text_data');

フォームじゃないけどURLからGETで受け取る場合

基本的には以下のような形式でパラメータを送る。 http://hogehoge.com/index/param1/param2/ ただし、以下のような形式でも、パラメータを送る事が可能。 http://hogehoge.com/index?p1=param1&p2=param2 この場合は、Controllerにて以下の方法で、受け取る。
$this->request->query('param1');
$this->request->query('param2');
まぁ、Apache側でmod_rewriteとか使えば如何様にもできますが。
タイトルとURLをコピーしました