Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

output XML
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

Hello Community,

I am wondering if anyone could show me how to create a module that outputs an xml file/feed. Our company works with many dynamic swfs. Does Magento have this capability?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

ok, maybe I should refine the question. Is it possible to create a module (aka new page) that doesnt use the templates. For instance could I create a model that did something like the following:

<?php
header('xml blablabla encoding blablabla');
$output = '<root>';
$output .= 'content of root';
$output .='</root>';

echo $output;
?>

And then a controller that accessed the model directly?

Can this be done anywhere without using a template or without html output?

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

A simple yes or no would be helpful.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@tman_f: definitely, you can create an action in a controller that would output anything you’d like.

There are posts and wiki articles about creation of controllers, and the documentation about creating custom modules is in works.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

Hi Moshe,

Thanks for your response. I have tried creating a controller that does the following:

class Mage_TestXml_IndexController extends Mage_Core_Controller_Front_Action 
{
    
public function indexAction()
    
{
        
echo "sample text";
    
}
}

I purposely left out the:
$this->loadLayout();
$this->renderLayout();

to avoid the templates. With this I get the following error:

exception ‘Zend_Controller_Response_Exception’ with message ‘Cannot send headers; headers already sent in C:\Program Files\xampp\htdocs\magento\app\code\local\Mage\TestXml\controllers\IndexController.php, line 7’ in C:\Program Files\xampp\htdocs\magento\lib\Zend\Controller\Response\Abstract.php:265

Is there a way to override this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Yes, if you do not wish to use Zend_Controller_Response_Http object, you should put exit; in the end of your action.

class Mage_TestXml_IndexController extends Mage_Core_Controller_Front_Action 
{
    
public function indexAction()
    
{
        
echo "sample text";
        exit;
    
}
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
tman_f
Sr. Member
 
Total Posts:  85
Joined:  2008-02-12
 

Thanks Moshe, that works great.

I hope you guys are proud of what you have made.

Great Product!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
cc96ai
Jr. Member
 
Total Posts:  16
Joined:  2008-01-22
 

I created a page in following directory
app\code\local\Mage\TestXml\controllers\IndexControllers.php

i got 404 Error

Whoops, our bad…
..
..

What else should I update ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@cc96ai: could you please outline all custom files for this module you have created?

 
Magento Community Magento Community
Magento Community
Magento Community
 
cc96ai
Jr. Member
 
Total Posts:  16
Joined:  2008-01-22
 

i only create a controller in following directory

app\code\local\Mage\TestXml\controllers\IndexControllers.php

<?
class Mage_TestXml_IndexController extends Mage_Core_Controller_Front_Action 
{
    
public function indexAction()
    
{
        
echo "sample text";
        exit;
    
}

?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
cc96ai
Jr. Member
 
Total Posts:  16
Joined:  2008-01-22
 

anything wrong on my code or anything setting did I miss ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
maltieri
Jr. Member
 
Total Posts:  1
Joined:  2011-09-02
 

Hi,

I know that it’s an old post, but anyway I’ll try.
Using the solution proposed in the thread I can create an xml using PHP code inside the controller.
The xml that I have to create is complex but almost static. It would be really helpful to use a php file with the xml and a few <?php ?> tags…

Is it possible?

 
Magento Community Magento Community
Magento Community
Magento Community
 
raulsanchez
Sr. Member
 
Avatar
Total Posts:  83
Joined:  2011-02-22
 
cc96ai - 05 March 2008 05:33 PM

i only create a controller in following directory

app\code\local\Mage\TestXml\controllers\IndexControllers.php

<?
class Mage_TestXml_IndexController extends Mage_Core_Controller_Front_Action 
{
    
public function indexAction()
    
{
        
echo "sample text";
        exit;
    
}

?>

Assuming you have set correctly your config.xml file
Try renaming your file to IndexController.php, not IndexControllers.php -> app\code\local\Mage\TestXml\controllers\IndexController.php

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top