CakePHP1.3.6:フォームの利用(GETで送信)
「cake勉強中さん」からコードの間違いを指摘していただきました。
どうもありがとうございました。tetsuya.odaka 2010/11/30
===========================================
前回は、以下の画面をmethod="post"で送信した。
今回は、getで送信して、コントローラーのparams変数として取得できる内容を確認する。
プログラム名はTestForm2とし、前回のログで作成した/app/controller下にある"test_form_controller.php"を、"test_form2_controller.php"としてコピーして以下のように変更する。
<?php class TestForm2Controller extends AppController{ public $name = 'TestForm2'; public $uses = null; public $layout = 'myznala'; public $autoLayout = true; public $autoRender = true; function index(){ $this->set('title_for_layout', "フォームのテスト2"); } function receive(){ $this->autoLayout = false; $this->set('title_for_layout', "フォームのテスト2(結果)"); var_dump($this->params); } } ?>
/app/views/test_formディレクトリは、test_form2ディレクトリとしてコピーする。"index.ctp"のformタグのアクション名を書き換える。
そして、/localhost/workspace/samplecake/TestForm2にアクセスすると以下の画面が得られる。
- "controller"=> string(8) "TestForm"
- "action"=> &string(7) "receive"
- "named"=> array(0) { }
- "pass"=> array(0) { }
- "plugin"=> NULL
- "form"=> array(0) { }
- "url"=> array(8) {
- "url"=> string(16) "TestForm/receive"
- "text1"=> string(9) "テスト"
- "text2"=> string(6) "tesuto"
- "text3"=> string(7) "hidden1"
- "select1"=> string(1) "3"
- "select2"=> array(2) { [0]=> string(1) "B" [1]=> string(1) "C" }
- "radio1"=> string(1) "b"
- "check1"=> array(2) { [0]=> string(3) "あ" [1]=> string(3) "う" }
}
となっている。
$this->params["url"][パラメータ名]
でパラメータが取得できる。