Welcome Guest, Not a member yet? Register   Sign In
What format should rows of data be in when passed from a Model back to a Controller?
#1

[eluser]callumd[/eluser]
I have plenty of experience with PHP/MySQL but very limited experience with frameworks and CodeIgniter.

I'm just trying to make sure I get my "best practises" sorted out nice and early.

I have a question:

Is it bad practise to pass a database object back to a controller from a model?

Eg, if I hit a database inside a model to get some data, should I convert it in to an array and pass back the array?

Or should the controller convert the database object in to an array?

Or should it never happen, and the database object should be passed "as is" on to the view which then loops over it displaying each row?

What is the best practise here?

Thanks.
#2

[eluser]dudeami0[/eluser]
The choice between and ArrayObject and Array is made in the model usually, choosing either $query->result() for an ArrayObject or $query->result_array() for an Array. Then just simply return either to your controller and it'll work like a charm.

Basic rule of thumb for what happens where is:

Controller handles incoming information and calls models and views
Model processes the input for output
View outputs the data, generally a UI
#3

[eluser]callumd[/eluser]
Thanks dudeami0. I'm not familiar with ArrayObject, I might look in to it.

I wasn't familiar with result_array(), this interests me as well.




Theme © iAndrew 2016 - Forum software by © MyBB