5

I have my RSS feed from controller returned /displayed on frontend using echo , how do I replace echo any alternate method availabale?

MEQP1.Security.LanguageConstruct.DirectOutput

public function execute()
{
        $shopUri = $this->_storeManager->getStore()->getBaseUrl();
        $posts = $this->collectionFactory->create()->addFieldToFilter('is_active', 1);

    $this->output .= '<?xml version="1.0" encoding="UTF-8"?>
    <rss version="2.0">
        <channel>
            <title><![CDATA['.$this->myHelper->getFinalIdentifier().']]></title>
            <description>Some Title</description>
            <link>'.$shopUri.'</link>
            <webMaster>'.$this->myHelper->getStoreEmail().'</webMaster>

            <image>
                <title><![CDATA['.$this->myHelper->getStorename().']]></title>

                <link>'.$shopUri.'</link>
            </image>';
    if (isset($posts) && $posts) {
        foreach ($posts as $post) {
            $url = $post->getIdentifier();
            $blog_link =  $shopUri.$this->myHelper->getDetailIdentifier($url);

            $this->output .= '
            <item>
                <title><![CDATA['.$post->getTitle().']]></title>
                <pubDate>'.date('r', strtotime($post->getPublishDate())).'</pubDate>
                <description>';
            if ($post->getImage()) {
                $this->output .= '<![CDATA[<img src="'.$this->myHelper->resizeImage($post->getImage(), 100, 75).'" title="'.$post->getTitle().'" alt="'.$post->getTitle().'" width="120"/>]]>';
            }
            $this->output .= '<![CDATA['.$post->getShortSummary().']]></description>';
            $this->output .= '
                <link>'.str_replace('&amp;', '&', htmlspecialchars($blog_link)).'</link>
                <guid isPermaLink="true">'.str_replace('&amp;', '&', htmlspecialchars($blog_link)).'</guid>
            </item>';
        }
    }
    $this->output .= '
        </channel>
    </rss>';
    echo $this->output;
 }

1 Answer 1

5

You can use following instead of echo

public function execute() {
    $data="bdfb";
    $resultJson = $this->resultFactory->create(ResultFactory::TYPE_RAW);
    $resultJson->setContents($data);
    return $resultJson;

}

Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.