Magento2 : Use of echo language construct is discouraged

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












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;










share|improve this question



























    up vote
    3
    down vote

    favorite












    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;










    share|improve this question























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      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;










      share|improve this question













      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;







      xml controllers marketplace rss-feed






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 5 hours ago









      Verdu

      957422




      957422




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          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






          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "479"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f245656%2fmagento2-use-of-echo-language-construct-is-discouraged%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            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






            share|improve this answer


























              up vote
              3
              down vote



              accepted










              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






              share|improve this answer
























                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                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






                share|improve this answer














                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







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 hour ago

























                answered 3 hours ago









                Qaisar Satti

                25.4k1154101




                25.4k1154101



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f245656%2fmagento2-use-of-echo-language-construct-is-discouraged%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery