Zend_Http_UserAgentã§ã®åå¥ããã¤ã¹ã¯ã©ã¹ã®è¨è¿°
Zend Framework1.11ã§ã¯ãZend_Http_UserAgentã¨ãããã©ã¦ã¶ããã¤ã¹ã®å種æ å ±åå¾å¤å®ã®ããã®ã³ã³ãã¼ãã³ããç»å ´ãã¾ãããç¾ç¶ããã©ã«ãã§ç¨æããã¦ããããã¤ã¹ã¯ã©ã¹(Zend_Http_UserAgent_Deviceã¤ã³ã¿ã¼ãã§ã¤ã¹ã®å®è£ )以å¤ã®ã¯ã©ã¹ãç¨æãããå ´åã®å©ç¨ã¡ã¢ã§ããããã§ã¯ãã¬ã©ãã´ã¹ã¨ããiPhoneã¨ãBlackã¹ãã¼ã¨ãã®ã¨ã¯ã¡ãã£ã¨ä¸çã®ä¸éã¨ã¯éé¢ãããããã¤ã¹ã«é¢ãã¦å¦çãããå ´åã®ã¯ã©ã¹ãç¨æãã¦ã¿ã¾ãã
ãµã¼ãã¼æ å ±ã¯ã(ZFã®ä»ã®ã³ã³ãã¼ãã³ãåæ§ã«ï¼Zend_Http_UserAgentã®ã¤ã³ã¹ã¿ã³ã¹çææã§ã®ã³ã³ãã£ã°ç¨å¼æ°ã«ããã°ããã使ç¨ãããªãå ´åã¯$_SERVERã°ãã¼ãã«å¤æ°ã§ãã
ããã¤ã¹åå¾æ å ±ãªã©ã¯ä¸æ¦storageã«æ ¼ç´ãããã®ã使ãåãããã§ããããã©ã«ãã¯Sessionã§ãã
ã¦ã¼ã¶å®ç¾©ã®ã¯ã©ã¹ãå©ç¨ããã«ã¯ããã¤ãæ段ãããã£ã½ãã§ããã
$config['mobile']['device']['classname'] = 'Test_Galapagos';
ã®ããã«è¨å®ããã¨åç´ã«ãã¼ãããã¾ãã
<?php class BarContoller extends Zend_Contoller_Action { public function fooAction() { $this->getHelper('ViewRenderer')->setNoRender(true); //ãããã°ç¨è¨å® $config['server'] = $this->getRequest()->getServer(); $config['server']['http_host'] = '192.168.0.1'; $config['server']['http_user_agent'] = 'willcom'; $config['storage']['adapter'] = 'NonPersistent'; $config['mobile']['device']['classname'] = 'Test_Galapagos'; $useragent = new Zend_Http_UserAgent($config); if ($useragent->getDevice()->getType() == 'galapagos') { echo '192.168.0.1ã¯ããããææãã¦ããIPã¢ãã¬ã¹ã§ã'; } else { echo 'sorry, Japanese Only'; } } } class Test_Galapagos extends Zend_Http_UserAgent_AbstractDevice { public static function match($userAgent, $server) { if ('192.168.0.1' === $server['http_host'] && preg_match('/^willcom/', $userAgent) ) { return true; } return false; } public function getType() { return 'galapagos'; } }
ã¦ã¼ã¶å®ç¾©ã¯ã©ã¹ã§ã¯ä¸è¨matchã¡ã½ããã§ã®å¤å®ã«ãã£ã¦ãã®ã¯ã©ã¹ãããã¤ã¹ã¯ã©ã¹ã¨ãã¦å©ç¨ããã決å®ããã¾ãã