Afficher un message
Vieux 16/06/2008, 07h23   #1
Daniel Smedegaard Buus
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Reading properties in non-instantiated child class from the parentclass

Hello there

I'm trying to implement some basic DRY MVC-like functionality as a
basis to work on. Specifically, I'd like to create a base abstract
model class with basic read, write, delete and update database
functionality, that I can use for all models in my code. I'd pretty
much like it to go like this (if there are a few errors, you'll have
to forgive me, I just woke up and I don't have the code on me, getting
ready to go to work, coffee not yet consumed :

abstract class CmsModel
{
protected static function getAll()
{
$query = "
SELECT
$(implode(', ', self::$attr_names))
FROM
self::$table_name
";
// ...etc...
}
// ...etc...
}

class RssFeed extends CmsModel
{
protected static $table_name = "RssFeed";
protected static $attr_names = array("id", "name", "url");
}

As you can probably tell, I'd like to be able to do a simple:

$rss_feeds = RssFeed::getAll();

in my code. But for this to work, CmsModel must be able to read the
two static properties that are only set in its derived classes, in
this example in RssFeed.

Is this possible? Everything works right now except this. I can
overridet getAll() in the children and simply call the parent function
with the right parameters, but this still means recreating the
functions in all subclass definitions. I'd like to skip that

Thanks in advance for any tips,

Daniel
  Réponse avec citation
 
Page generated in 0,04813 seconds with 9 queries