$request = $this->get('request');
$request->isXmlHttpRequest(); // Ajax のリクエストかどうか?
$request->getPreferredLanguage(array('en', 'fr'));
$request->query->get('page'); // $_GET のパラメータを取得
$request->request->get('page'); // $_POST のパラメータを取得
リダイレクト
public function indexAction()
{
return $this->redirect($this->generateUrl('homepage'));
}
return $this->redirect($this->generateUrl('homepage'), 301);
オブジェクトを配列へ変換
function object_to_array($obj) { $_arr = is_object($obj) ? get_object_vars($obj) : $obj; foreach ($_arr as $key => $val) { $val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val; $arr[$key] = $val; } return $arr; }
その2
function _object_to_array($object) { $new = NULL; if( is_object($object) ){ $object=(array)$object; } if( is_array($object) ){ $new = array(); foreach( $object as $key => $val ){ $key = preg_replace("/^\\0(.*)\\0/","",$key); $new[$key] = $this->_object_to_array($val); } } else{ $new = $object; } return $new; }