【发布时间】:2014-02-05 18:53:54
【问题描述】:
我是 CakePHP 的新手,我正在尝试设置一个返回 json 或 xml 数据的基本控制器,方法是按照 cakephp 网站上的指南进行操作。 http://book.cakephp.org/2.0/en/development/rest.html
问题是它在 json 和 xml 的情况下都会返回一堆多余的标记。我现在正试图弄清楚 xml 发生了什么,因为最明显的是看到什么被破坏了。它说它应该返回如下内容:
<recipes>
<recipe id="234" created="2008-06-13" modified="2008-06-14">
<author id="23423" first_name="Billy" last_name="Bob"></author>
<comment id="245" body="Yummy yummmy"></comment>
</recipe>
<recipe id="3247" created="2008-06-15" modified="2008-06-15">
<author id="625" first_name="Nate" last_name="Johnson"></author>
<comment id="654" body="This is a comment for this tasty dish."></comment>
</recipe>
</recipes>
而是返回类似的东西:
<resources>
<recipes>
<recipe id="234" created="2008-06-13" modified="2008-06-14">
<author id="23423" first_name="Billy" last_name="Bob"></author>
<comment id="245" body="Yummy yummmy"></comment>
</recipe>
</recipes>
<recipes>
<recipe id="3247" created="2008-06-15" modified="2008-06-15">
<author id="625" first_name="Nate" last_name="Johnson"></author>
<comment id="654" body="This is a comment for this tasty dish."></comment>
</recipe>
</recipes>
</resources>
查看模型查找函数返回数据的方式可能是由于返回的数组的结构。我可以改变周围的结构,但想确保我没有错过任何东西。
【问题讨论】:
-
您可以将您发送的代码粘贴到视图中吗?