Take data from a db in a class in codeigniter

Asked

Viewed 105 times

0

good day, I’m making a shopping cart and in it I have a function to list the products, and return me an array to then I list in my view more I don’t know if it would be the right one to do it in my class or inside a model and a controller, plus what I need is to get the database data I need to know if it is possible to do it directly in the class or I have to do it with model and controller. thanks to all our friends

1 answer

2


Well, first of all, as a good MVC practice, it is always better to treat the information that comes from the database in the Model classes. Can you do it in the controller? Yes. Is it true? I don’t think so. It’s best to create a select method in your model that goes back to your controller. That way, in other controllers that you need that same information, just search the model by the method and it comes ready.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.