set(array('posts' => $posts, 'serialize' => 'posts'));` * * When the view is rendered, the `$posts` view variable will be serialized * into XML. * * **Note** The view variable you specify must be compatible with Xml::fromArray(). * * If you don't use the `serialize` key, you will need a view + layout just like a * normal view. * * @package Cake.View * @since CakePHP(tm) v 2.1.0 */ class XmlView extends View { /** * Constructor * * @param Controller $controller */ public function __construct($controller) { parent::__construct($controller); if (is_object($controller)) { $controller->response->type('xml'); } } /** * Render a XML view. * * Uses the special 'serialize' parameter to convert a set of * view variables into a XML response. Makes generating simple * XML responses very easy. You can omit the 'serialize' parameter, * and use a normal view + layout as well. * * @param string $view The view being rendered. * @param string $layout The layout being rendered. * @return string The rendered view. */ public function render($view = null, $layout = null) { if (isset($this->viewVars['serialize']) && is_array($this->viewVars['serialize'])) { return $this->output = Xml::fromArray($this->viewVars['serialize'])->asXML(); } return parent::render($view, $layout); } }