Create collections of objects
| From: | Emilio Astarita | Date: | Thu, 14 Feb 2008 22:06:32 +0000 |
| Subject: | Create collections of objects | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-269332@lists.php.net to get a copy of this message | ||
Hi people,
I want a class that allows create objects that get the information
consulting the DB. So, I am thinking to do something like this:
class element {
public __construct($id,$type = 'id') {
switch($type) {
case 'id':
$where = sprintf(" id = %d ",$id);
break;
case 'name':
$where = sprintf(" name = %s ",escape($id));
break;
//...
// get the row and call setName($row['name'])...
}
}
}
This works fine, but also I want a good way (efficient) of getting a
collection of these objects. I can't figure a convenient way. A static
function its a good posibility? I have some ideas but they imply public
setters of the class `element'.
Thanks for any help.
--
Emilio Astarita <emilio.astarita@gmail.com>
Gnus
http://gnus.org/
<http://www.gnu.org/philosophy/free-sw.html>