XF 2.2 How to create a custom XML/RSS response?

noxa

Member
Hello,

I want to create a custom XML/RSS response page for my forum. I have created a public controller -

Code:
<?php
namespace XTest\Mrss\Pub\Controller;
use XF\Pub\Controller\AbstractController;
class Mrss extends AbstractController
{
  public function actionIndex()
  {
    $MrssRepo = $this->app->repository('XTest\Mrss:Mrss');
    $entries = $MrssRepo->findMrss();
    $Mrss = $entries->fetch();
    
    $templateParams = [
      'Mrss' => $Mrss,
    ];
    $xmlData = $this->app->templater()->renderTemplate('public:XTest_mrss', $templateParams);
    $dom = new \DOMDocument('1.0', 'utf-8');
    $dom->preserveWhiteSpace = FALSE;
    $dom->loadXML($xmlData);
    $dom->formatOutput = TRUE;
    
    $viewParams = [
      'xml' => $dom->saveXML()
    ];
    $this->setResponseType('xml');
    return $this->view('XTest\Mrss:Mrss', 'XH', $viewParams);
  }
}

XTest_mrss template content

Code:
<rss version="2.0">
    <channel></channel>
</rss>

XH template content

Code:
{{ $xml }}

I have created the public router, but when I try to access it, I am getting -

Code:
<errors>
<error>
<![CDATA[ The requested page cannot be represented in this format. ]]>
</error>
</errors>

Please, help me find a better solution. Thanks!
 
Back
Top Bottom