PHP锂电(li3)如何使用JSON设置自动响应 [英] PHP lithium(li3) how to set up automatic response with JSON

查看:118
本文介绍了PHP锂电(li3)如何使用JSON设置自动响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以这种方式设置了一个锂电应用程序,所以当

I have a lithium app set up that way, so when

return($data) 

用于它,或者可以在锂view.html.php中用作

is used it either can be used in the lithium view.html.php as

echo $data

或者如果请求标头"accept"等于"json/javacript",它将返回类似的内容

or if request header "accept" equals "json/javacript" it would return something like

{
data: { a:'b' }
}

自动.

不幸的是,在我作为测试应用程序制作的新应用程序中,流程没有发生(并且始终返回HTML).

Unfortunately in the new app that I made as a test app that flow is not happening (and only HTML is always returned).

经过一些研究后,如果我取消评论,似乎应该自动完成

After doing a little research it seems like that it is supposed to be done automatically if I uncomment

require __DIR__ . '/bootstrap/media.php';

inside bootstrap.php里面,但是没有用,我仍然返回了HTML.我下载了锂框架的最新版本(我可能在1个月或2个月前下载了

inside bootstrap.php But that didn't work, I still have HTML returned. I downloaded a recent version of the lithium framework(I downloaded it may be 1 or 2 months ago)

有人知道是否需要使用JSON进行自动响应吗?

Anybody knows if automatic response with JSON requires some set up or not?

推荐答案

取自 http://dev.lithify.me/lithium/tickets/view/353

然后从锂文件中获取

要启用自动内容类型协商(即根据HTTP Accept标头的值确定响应的内容类型),请将"negotiate"标志设置为true.否则,响应将仅基于请求对象的type参数(如果Request参数中没有类型,则默认为'html')

To enable automatic content-type negotiation (i.e. determining the content type of the response based on the value of the HTTP Accept header), set the 'negotiate' flag to true. Otherwise, the response will only be based on the type parameter of the request object (defaulting to 'html' if no type is present in the Request parameters)

http://li3.me/docs/lithium/action/Controller : :$ _ render

http://li3.me/docs/lithium/action/Controller::$_render

如果您需要更多有关实施方面的帮助,请发表评论.

If you need more help on how to implement leave a comment.

这篇关于PHP锂电(li3)如何使用JSON设置自动响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆