Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

首页每日一句的问题 #9

Closed
scriptwang opened this issue Aug 24, 2019 · 3 comments
Closed

首页每日一句的问题 #9

scriptwang opened this issue Aug 24, 2019 · 3 comments

Comments

@scriptwang
Copy link

和这个问题一样 #5 ,我的环境是PHP5,有两个问题,

  • 一个问题是获取每日一句失败
    file_get_contents已打开,allow_url_fopen = On也已经打开,PHP报错信息
PHP message: PHP Warning:  file_get_contents(): Unable to find the wrapper "compress.zlib" - did you forget to enable it when you configured PHP? in /srv/usr/themes/cactus/functions.php on line 508
PHP message: PHP Warning:  file_get_contents(compress.zlib://https://rest.shanbay.com/api/v2/quote/quotes/today/): failed to open stream: No such file or directory in /srv/usr/themes/cactus/functions.php on line 508

这个报错打开该文件/srv/usr/themes/cactus/functions.php,找到508行,将

$json = file_get_contents("compress.zlib://".'https://rest.shanbay.com/api/v2/quote/quotes/today/');

改成

$json = file_get_contents('https://rest.shanbay.com/api/v2/quote/quotes/today/');

貌似是因为PHP5不支持compress.zlib的原因

  • 第二个问题是前端没将json字符串转成对象

image
打开/srv/usr/themes/cactus/footer.php,找到片30行,添加一句

data = JSON.parse(data);

如图
image

然后就能正常显示了
image

@Seevil
Copy link
Owner

Seevil commented Aug 26, 2019

compress.zlib报错 你看下你php的zlib组件 有没有启用?
然后菜鸡请教一下 json字符串转成对象 有什么作用哈?一脸懵逼代码复制的别人的。

@scriptwang
Copy link
Author

compress.zlib报错 你看下你php的zlib组件 有没有启用?
然后菜鸡请教一下 json字符串转成对象 有什么作用哈?一脸懵逼代码复制的别人的。

  • compress.zlib
    应该是我的compress.zlib没启用,对PHP不熟,报错的直接都删掉了/捂脸
  • json字符串转成对象
    你看代码里面。如果不转对象的话,data.data是取不到东西的,是undefined,后面会报错
    image

@Seevil
Copy link
Owner

Seevil commented Sep 2, 2019

@scriptwang 哦哦,data.data取不到东西应该是你json 是空的或者不存在,因为我一直都是正常的哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants