Hey,
I’m looking for a bit of advice here, I have a simple model with the usual save, delete and find methods, but wanted to create a getAll method aswell, it feels wrong putting it in the model as its not related to the actual model. Which way should I design this?
My current model looks like this:
<?php
class User {
$id;
$name;
$address;
public function __construct() {
// do some constructor stuff
}
public function save() {
// insert into....
}
public function delete() {
// delete from user where ....
}
public function find($id) {
// select * from user where ...
}
}
?>
Any help would be much appreciated,
Thanks
Well, after you have methods for finding, creating and deleting users, there’s nothing to worry.
In my opinion, there are two approaches
1) You can use your
find()method in a special way, in order to get all users (a bit of a hack)2) You can create a public static method
getAll()to do the job (I think it should be static, becausegetAll()is not related to a single instance of User object)