我应该将对象或普通数据传递到视图中吗?
我正在建立一个类似于 Facebook 的时间表……包含不同类型的帖子,每种帖子都涉及各种数据,但仍然高度模板化。
我想知道是否最好将大型多维数组传递到每个子视图(时间轴上的每个项目)中,或者是否最好简单地传递对象(例如“用户”对象),以便子视图可以使用对象的功能?
其中一个比另一个更灵活吗?有人知道 Facebook 如何处理这个问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,数组是个坏主意。许多框架将对象传递给视图,但也有一些框架将对象放入视图数组中(例如 cakePHP)。
我使用蛋糕并在视图中使用“数组”数据是噩梦
使用对象,它们是为了简化我们的生活;]
In my opinion arrays are bad idea. Many frameworks passes objects to views, but there are also ones which puts into view arrays (cakePHP for example).
I worked with cake and working with "arrayed" data in views was nightmare
Use objects, they are for simplify our lifes ;]
我无法告诉你 facebook 如何处理这个问题,但通常对象通常更灵活。
您可以使用
__toString
函数来回显它们如果您使用
ArrayAccess
接口。一般来说:对象比静态数组更具动态性,因此对象更灵活。
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.