douke1891 2011-10-25 17:40
浏览 34
已采纳

我应该将对象或普通数据传递给视图吗?

I'm building a timeline similar to Facebook's...with different types of posts, all sorts of data involved with each, but still highly templatized.

I am wondering if it's better to pass large multidimensional arrays into each sub-view (each item on the timeline), or if it's better to simply pass objects in (such as a "user" object), so that the sub view can use the functions of the object?

Is one more flexible than the other, and does anybody know how Facebook handles this?

  • 写回答

2条回答 默认 最新

  • doulu5717 2011-10-25 18:39
    关注

    I can't tell you how facebook handles this, but normally objects are generally more flexible.

    You can just echo them by using the __toString function for example. If all objects that get passed into view are automatically decorated, this can be extremely flexible.

    They can behave like arrays, if you use the ArrayAccess interface.

    Generally: Objects are just more dynamical than arrays which are static, so objects are more flexible.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?