Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to pass data to shared view where data is once read with ORM or queried with DB::select?
  • If you read a row from DB using ORM and passing that object to a view then in a view you would do something like $object->field to access a certain field. What if this view is called in another controller where the row is fetched using Database class with DB::select()->execute()? In this way $object->field would not work anymore... How do you pass data to the view so that view can access data in the same way? Second question. Can ORM use Database query builder methods for filtering out data (or_where, and_where and so on)?
  • Use a Viewmodel to unify the data? As to your second question, check Orm/classes/query.php so see what exactly is supported.
  • Harro Verton wrote on Thursday 19th of January 2012:
    Use a Viewmodel to unify the data?

    Ok this was my first thought, but what when I am passing an array of record from db? Isn't this then doing double work? First iterating trough array of results/objects in Viewmodel to unify the data, and then iterating again in View to outpu the data? This also unecessary extends the execution time...?! Am I wrong?
  • Well, it's your choice to retrieve data in different formats. Alternative is to deal with this in your model, and make sure the results are returned in the same format. But in the end, whether you do it in your model, controller, viewmodel or view, you'll have to convert.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion