【问题标题】:Make an rss feed with Laravel 5.1使用 Laravel 5.1 制作 RSS 提要
【发布时间】:2016-04-05 15:56:04
【问题描述】:

我使用 Laravel 5.1 制作应用程序,只是我需要在 RSS 提要中以 XML 格式获取一些帖子。

我正在使用 Laravel 5.1。我为 Laravel 4 找到了很多不适用于 5.1 的解决方案。

我尝试了这段代码,但我怎样才能查看我的数据?

return response('rss', 200,['Content-Type'=> "application/xml"]);

还有这个

return response($posts, 200,['Content-Type'=> "application/xml"]);

但此代码仅返回 json 数据。

【问题讨论】:

    标签: rss laravel-5.1


    【解决方案1】:

    谢谢大家这是我的代码

        $xml = new \XMLWriter();
        $xml->openMemory();
        $xml->startDocument();
        $xml->startElement('users');
        foreach($users as $user) {
            $xml->startElement('data');
            $xml->writeAttribute('id', $user->id);
            $xml->writeAttribute('firstname', $user->firstname);
            $xml->writeAttribute('lastname', $user->lastname);
            $xml->writeAttribute('email', $user->user->name);
            $xml->endElement();
        }
        $xml->endElement();
        $xml->endDocument();
    
        $content = $xml->outputMemory();
        $xml = null;
    
        return response($content)->header('Content-Type', 'text/xml');
    

    回答网址

    How can i store data from mysql to XML in Laravel 5?

    【讨论】:

      猜你喜欢
      • 2020-06-08
      • 2016-11-04
      • 2011-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多