【问题标题】:How to use SimplePie with Laravel如何在 Laravel 中使用 SimplePie
【发布时间】:2016-05-19 14:22:56
【问题描述】:

我正在使用 Laravel 5.2。我需要使用 SimplePie 获取 RSS 提要,所以我通过 composer.json 安装库,现在我的供应商文件夹包含 simplepie,但是当我运行以下代码时,此错误显示:

SimplePie.php 第 1379 行中的 ErrorException:./cache 不可写。 确保您设置了正确的相对或绝对路径,并且 该位置是服务器可写的。

我的路线代码:

Route::get('feed', function () {

$feed = new SimplePie();

$feed->set_feed_url(array(
    'http://www.thenews.com.pk/rss/2/16' //it has no images
));
$feed->init();
$itemCount=$feed->get_item_quantity();
return $itemCount;
});

【问题讨论】:

  • 你有什么问题?您尝试过什么自己来解决错误?
  • 错误看起来很简单。
  • 在您的问题标题中添加“Pie”。

标签: laravel simplepie


【解决方案1】:

检查 ./cache is not writeable 无法写入缓存文件夹检查此文件夹的权限或尝试使用 SimplePie 的 L5 包装器 https://github.com/willvincent/feeds

【讨论】:

    【解决方案2】:

    在/storage/文件夹中为simplepie创建一个可写的缓存文件夹(我叫我的simplepie_cache)。

    在您的提要对象中设置路径:

    $feed->set_cache_location(storage_path() . '/simplepie_cache');

    这应该可以解决问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-08
      • 1970-01-01
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多