I want to pass a user id value in variable $userID, to a function in a Model class Clientmodel. The function is get_username(), now in a model do I have to define that function to accept a variable as a parameter? so.. get_username($userID)? Just want to know how is the recommended way in code igniter?
Thanks!
tariq
That really depends on what you use the model for. Most of the time, it will make sense to have a parameter to the method and use that every time:
On the other hand, sometimes it makes sense for the Model to be “stateful” — do you have one userID per controller? Will it ever be more than one? Do you need the userID in a large number of methods of that model? Then maybe this will make sense instead:
Other times, you may have one userID which you plan on using over and over, but sometimes you need to use another value, that is when default arguments come into play: