generating and storing xml files in yii

HI!!

I am new to yii and want to generate and store xml file. I have created a module for admin and inside it have created a controllor GenerateXML.php but have not idea how can I generate and store XML file

I have used Yii Widgets to do this on several projects. Extend the widget class with your own, and override the run method. In the same directory as your Widget class, add a views directory that has any views (for XML they could be XML templates) Like this:




widgets/

  MyWidget.php

  views/

    xmlTemplate.php



In the run method I will typically run the render method, passing in the view name, any parameters that I want to send to the view, and true as the 3rd parameter (which will return the results as a string instead of sending to the output buffer)




class MyWidget extends \CWidget

{

    public $foo;

	

    function run()

    {

        return $this->render('xmlTemplate', array('foo'=>$this->foo), true);

    }

}



This would be an example of xmlTemplate.php




<?php echo '<?xml version="1.0"?>'; ?>

<foo>

<?php echo $foo ?>

</foo>



Then you can use it like so:




$xmlWidget = new MyWidget;

$xmlWidget->foo = 'bar';

$output = $xmlWidget->run();

file_put_contents('someFile.xml', $output);