Telling cakePHP to render as XML / use xml/blah.ctp instead of blah.ctp



I have been successfully using XML view files in CakePHP (request the XML output type in headers so CakePHP will use e.g. Orders/xml/create.ctp instead of Order/create.ctp).


However, now i need to add some functionality that requires me to the reformat the XML at the end of most business logic in the controller.


So i tried this in the controller action:



public function createorder() {
$this->autoRender = false; // disable automatic content output
$view = new View($this, false); // setup a new view

{ ... all kinds of controller logic ...}

{ ... usually i would be done here and the XML would be outputted, but the autorender will stop that from happening ... }

{ ... now i want the XML in a string so i can manipulate the xml ... }
$view_output = $view->render('createorder'); // something like this

}


But what this gives me is:



<?xml version="1.0" encoding="UTF-8"?>
<response>
<error>View file &amp;quot;/Users/test/Documents/hosts/mycakeapp/app/View/Orders/createorder.ctp&amp;quot; is missing.</error>
<name>MissingViewException</name>
<code>500</code>
<url>/orders/createorder/</url>
</response>


So i need to tell CakePHP to pickup the xml/createorder.ctp instead of createorder.ctp. How do i do this?


Cheers!


No comments:

Post a Comment