0

I am about to ask a more general conceptual question as apposed to a coding issue. I have recently started using the codeigniter framework and am trying to learn the principles of MVC - so please be patient. I roughly accept this as a really simplistic way of looking at MVC.

  • Models - Core logic of the system that passes data from DB to the controller
  • Controller - Glue that holds the system together and allows data from the view to be passed to the model and vice versa
  • View - The view that a user should see within the browser - some form data will be firstly passed to the controller.

*But I was wondering more about the ability of the model. For example, can data from the database be pulled from the model and stored? For example, could the model hold an array of names say that I have queried back from the database? Could I then display these to the user 1 by 1 using a button to increment a pointer to point to the next name in the array for example. I apologize if this is a stupid question just trying to figure out how data from the db is handled within the model.

SAT
  • 647
  • 1
  • 12
  • 23
TotalNewbie
  • 1,004
  • 5
  • 13
  • 25
  • 1
    You will be in [trouble trying to learn MVC with CodeIgniter](http://stackoverflow.com/a/13821880). Instead [read more about the model here](http://stackoverflow.com/a/5864000). – Antony Jan 08 '14 at 11:11

1 Answers1

0

can data from the database be pulled from the model and stored? for example could the model hold an array of names say that I have queried back from the database?

The purpose of the model is to represent the data/state of the application. The implementation (data pulled and cached in a model object) doesn't matter. The model is supposed to allow the view to show itself and allow the controller to modify itself. There should be no business logic in the model (that's what the controller is there for). So, yes, the model can store data from a database.

could I then display these to the user 1 by 1 using a button to increment a pointer to point to the next name in the array for example

The presentation logic, or how you display a model to the user is a responsibility of the view. The model should allow the view to query the data, and then display it.

Shoe
  • 74,840
  • 36
  • 166
  • 272