Zend_Rest_Serverã«ã¤ãã¦
ZendFrameworkã«ã¤ãã¦ãã£ã¤ããããããã£ããã ãã©ï¼æ¸ãã®ãé¢åã§æ´æ°ãæ»ã£ã¦ã¾ãããï¼è½ã¡çãã¦ããã®ã§å°ãè¨äºãæ¸ãã¦ããããã¨æãã¾ãï¼
ã¾ãã¯ï¼xmlãè¿ããããªã·ã¹ãã ãä½ãããã«ä½¿ã£ãZend_Rest_Serverã«ã¤ãã¦ï¼Content-Typeã¨ããåæã«text/xmlã«ãã¦ãããã®ã§ä¾¿å©ãªãã§ããï¼å ¬å¼ã®ããã¥ã¡ã³ãèªãã§ãæå³ãããããªãã¦ããªãæªæ¦è¦éãã¾ããï¼ï¼å ¬å¼ï¼http://framework.zend.com/manual/ja/zend.rest.server.htmlï¼
æ¸ãã¦ãéããã£ã¦ãã®ã«åããªãï¼ã©ããªã£ã¦ãã®ã£ã¦æãã ã£ãï¼ã ããä¸çæ¸å½ã°ã°ã£ããã ãã©ï¼ã°ã°ãã©ãã°ã°ãã©ãï¼ããè³æãè¦ã¤ãããªãï¼æå¾ã¯ï¼æµ·å¤ã®ãã©ã¼ã©ã ããã¾ãã£ã¦ï¼ãã£ã¨ãããããããµã³ãã«ãã¿ã¤ãããã¨ãã§ããï¼ï¼http://blog.ekini.net/2009/04/17/zend-framework-a-simple-zend_rest_server-example/ï¼
以ä¸ï¼http://localhost/zend/123ã®ãããªæãã§ã¢ã¯ã»ã¹ãæ³å®ããããã°ã©ã ï¼123ã¯idã¨ãã¦ã«ã¼ãã£ã³ã°ãã¦ããã¾ãï¼
//indexAction $params = $this->_getAllParams(); $request = çç¥...; $server = new Zend_Rest_Server(); $server->setClass('XmlServer'); $server->handle($request); //XmlServer.php class XmlServer { private $xmlString = '<?xml version="1.0" encoding="UTF-8"?><response></response>'; public function getById($id) { $xml = new SimpleXMLElement($this->xmlString); //ãã¼ã追å å¦çã¯çç¥ return $xml; } }
åãåã£ããã©ã¼ã¡ã¿ãä¸ã®ãµã¤ãã«ããããã«
Array ( [method] => getById [id] => 123 )
ã®ãããªé åã«ãã¦$requestãä½æï¼ãã®é åã®methodã®é¨åãsetClassã§æå®ããã¯ã©ã¹ã§ãã°ãããã¨ã«ãªãããã§ãï¼ããã«ï¼æ®ãã®ãã©ã¡ã¼ã¿ï¼ããã§ã¯[id] => 123ï¼ã®å¤ããã®ã¡ã½ããã®å¼æ°ã¨ãã¦æ¸¡ããã¾ãï¼åãåãå´ã¯ï¼
getById($id)
ã®ããã«ãã¦åãåããã¨ãã§ãã¾ãï¼ã¾ãï¼$requestã®ãã©ã¡ã¼ã¿ãâãããªãããã§è¤æ°ããã¨ãã¯ï¼
Array ( [method] => getById [id] => 123 [name] => hogeo )
getById($id, $name)
ã®ããã«ãã¦åãåããã¨ã«ãªãã¾ãï¼ãã©ã¡ã¼ã¿ã®æ°ã«åããã¦è¯ããªã«ãã£ã¦ãããã®ã§æ¥½ã§ããã§ãï¼åå¨ããªãã¡ã½ãããå¼ãã ã¨ãã®ã¨ã©ã¼å¦çã¨ãããã£ã¦ããã¾ãï¼