So, basically I have a String named $xmlString
. It's already well-formed. I'd like to save this String temporarily into a XML-file (precisely: a OPML) and send it to a email address.
I receive the email, it is a file with the .opml extension, but it is not filled with the content of $xmlString
, but filled with html of the view. (you could look at it here)
This is my Controller:
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');
App::uses('File', 'Utility');
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
// Set XML
if ($this->RequestHandler->isXml()) {
$this->RequestHandler->setContent('xml');
}
}
public function sendOpml($xmlString) {
$this->autoRender=false;
$xmlString=$this->render();
//here is something wrong...
file_put_contents(TMP.'podcasts.opml', $xmlString);
$Email = new CakeEmail('default');
$Email->from(array('[email protected]' => 'Podcaster'));
...
$Email->attachments(array(
'podcasts.opml' => array(
'file' => TMP.'podcasts.opml',
'mimetype' => 'text/x-opml')));
$Email->send('My message');
}
}
?>
Could somebody explain me why it is not the original string in there?
The problem was the random render in the action
public function sendOpml($xmlString) {
$this->autoRender=false;
$xmlString=$this->render(); /*this is the problem */
Since the string was already well formatted (and anyway it's not really pretty to assign a render() to a variable), there was no need to handle it that way before putting it in a file to be attached.