I’m just going to give the code from a project that I’m working, so substitute in your own names where necessary.
Files to create:
Files to modify:
In general, the approach is as follows. Create a layout that wraps our XML and outputs the XML header.
Step 1: Create The View Files
For the layout file, make sure you have at least the bolded text below included:
<?php header("Content-type: text/xml"); ?>
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'?>
<Tag><?php echo $content; ?></Tag>
I’ll leave it up to you to figure out how you want to wrap your data with xml tags.
Next, create the view file for the action. This can be as complex as you want it to be. Here’s an extremely simple example showing the output of just one variable.
<?php echo CHtml::encode($model->getAttributeLabel('name')); ?>:
<?php echo CHtml::encode($model->name); ?>
Step 2: Edit the Controller
Now you want to tell your controller which files to use. Create a new action in your controller and make sure you assign both the layout file you created and the action view.
public function action[your_action]($id)
$this->layout = "[your_layout]";
Lastly, make sure that you have allowed access to your new action if that’s a necessity.
If others have a better means of doing this, do let me know in the comments and I’ll update this howto.
I found the following pages for reference when investigating the issue to begin with.