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?
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.
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
$data['blah']['bleh']['bluh']['puh']['some_other_long_array_key_for_difference']['and']['so']['on']['fuuuuuu']
Use objects, they are for simplify our lifes ;]