Welcome Guest, Not a member yet? Register   Sign In
MVC question
#1

[eluser]wyred[/eluser]
When studying about MVC, most examples show that we code our model in the form of a singular object. (i.e. User instead of Users).

So for example, to get the name of a user with the ID 2,
$user = new User(2);
$user->get_name();

What if I want to show a list of users?

Do I code a Users model? So all I need to do is just $Users->get_list(); ?

Hope I didn't sound confusing.
#2

[eluser]Spelljack[/eluser]
Unite them in Users model. There is only "s" letter between User and Users. This make you easy to typo
#3

[eluser]InsiteFX[/eluser]
Database table names are usually plural users
and model names are usually singular user

But this has started many Debatable wars!

But you will find that most CI users stick to this naming convention.

InsiteFX
#4

[eluser]wyred[/eluser]
It's not the naming convention that I'm concerned about.

It's just whether it makes sense to have a User model contain a function that returns the name of a user, together with a function that returns a list of users in the database.

Theoretically, it doesn't sound right.
#5

[eluser]InsiteFX[/eluser]
Well the way I handle it is to have a get method and a get_all method.

InsiteFX
#6

[eluser]wyred[/eluser]
I see.... thanks!




Theme © iAndrew 2016 - Forum software by © MyBB