{"id":337,"date":"2011-09-09T15:25:23","date_gmt":"2011-09-09T13:25:23","guid":{"rendered":"http:\/\/webpiraten.de\/?p=337"},"modified":"2012-01-22T20:27:07","modified_gmt":"2012-01-22T19:27:07","slug":"agavi-output-type-overwrite-in-action","status":"publish","type":"post","link":"https:\/\/webpiraten.de\/index.php\/frameworks\/agavi-output-type-overwrite-in-action\/","title":{"rendered":"agavi output type overwrite in action"},"content":{"rendered":"<p>um den output type einer agavi action auch nach dem routing zu \u00e4ndern, kann man innerhalb der action den output type \u00fcberschreiben.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\r\n\/**\r\n * assume that 'html' is the standard GET output for this action\r\n * when this action is called via POST you want to change the output type to 'json'\r\n * because on error or success you want to show small messages per json instead full html\r\n *\/\r\n    public function executeRead(AgaviRequestDataHolder $rd)\r\n    {\r\n        return 'Input';\r\n    }\r\n\r\n    public function executeWrite(AgaviRequestDataHolder $rd)\r\n    {\r\n        $this-&gt;getContainer()-&gt;setOutputType($this-&gt;getContext()-&gt;getController()-&gt;getOutputType('json'));\r\n        try\r\n        {\r\n            \/\/ do POST stuff\r\n        }\r\n        catch(Exception $e)\r\n        {\r\n            $this-&gt;setAttribute('message', $e-&gt;getMessage());\r\n            return 'Error';\r\n        }\r\n        return 'Success';\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>um den output type einer agavi action auch nach dem routing zu \u00e4ndern, kann man innerhalb der action den output type \u00fcberschreiben. \/** * assume that &#8218;html&#8216; is the standard GET output for this action * when this action is called via POST you want to change the output type to &#8218;json&#8216; * because on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,3,50,5],"tags":[275,8,276,169,274,273,205],"class_list":["post-337","post","type-post","status-publish","format-standard","hentry","category-agavi-framework","category-frameworks","category-javascript","category-php","tag-action","tag-agavi","tag-container","tag-output","tag-overwrite","tag-set-output-type","tag-type"],"_links":{"self":[{"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/posts\/337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/comments?post=337"}],"version-history":[{"count":2,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/posts\/337\/revisions"}],"predecessor-version":[{"id":354,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/posts\/337\/revisions\/354"}],"wp:attachment":[{"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/media?parent=337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/categories?post=337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webpiraten.de\/index.php\/wp-json\/wp\/v2\/tags?post=337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}