使用symfony2.8创建新的xml文件并保存在系统中 [英] Create new xml file and save in system using symfony2.8

查看:33
本文介绍了使用symfony2.8创建新的xml文件并保存在系统中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建.xml文件并使用symfony2.8直接从控制器保存,xml文件应该是自动附加的创造了一天.

I want to create .xml file and save into directly from controller using symfony2.8, xml file should be auto append once it created for a day.

帮助将不胜感激

$mainNode = new \SimpleXMLElement("<?xml version='1.0' encoding='UTF-8'?><items></items>"); 
$productNode = $mainNode->addChild('product');
$productNode->addChild( 'productCode', '1235846' );
$mainNode->asXML();

推荐答案

你可以这样做:

public function updateTodaysXMLAction()
{
    $todaysFile = '/path/to/file/' . date('d-m-Y').'.xml';
    $xmlFileContents = file_get_contents($todaysFile);
    $xml = new \SimpleXMLElement($xmlFileContents);
    //make updates as needed
    $xml->addChild('product')->addChild( 'productCode', '1235846' );
    // Save out the file
    $xml->asXML($todaysFile);
}

这篇关于使用symfony2.8创建新的xml文件并保存在系统中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆