■リクエスト情報を取得するメソッド
- getQuery()
- $_GET
- getPost()
- $_POST
- getCookie()
- $_COOKIE
- getServer()
- $_SERVER
- getEnv();
- $_ENV
■パラメータの取得
以下のようにレスポンスオブジェクトがgetQuery()メソッドをコールするとURIでhogeに対応した値が表示される。
<?php require_once 'Zend/Controller/Action.php'; class IndexController extends Zend_Controller_Action { public function indexAction() { $response = $this->getResponse(); $response->appendBody($this->getRequest()->getQuery('hoge')); } }
以下のようにカレントオブジェクトが_getParam()メソッドをコールするとURIでhogeに対応した値が表示される。通常は_getParam()メソッドの使用が好ましい。
<?php require_once 'Zend/Controller/Action.php'; class IndexController extends Zend_Controller_Action { public function indexAction() { $response = $this->getResponse(); $response->setBody($this->_getParam('hoge')); } }
以下のようにするとhogeに対応した値が存在するかチェックする。
<?php require_once 'Zend/Controller/Action.php'; class IndexController extends Zend_Controller_Action { public function indexAction() { $response = $this->getResponse(); if($this->_hasParam('hoge')){ $response->setBody($this->_getParam('hoge')); } } }