views:

39

answers:

1

If I would like to have several static methods in my models so I can say User::get_registered_users() and have it do something like

public static function get_registered_users()
{
    $sql = "SELECT * FROM `users` WHERE `is_registered` = 0";
    $this->db->query($sql);
    // etc...
}

Is it possible to access the $this->db object or create a new one for a static method?

A: 

Matt S is correct, though Kohana was built for PHP5, so previous compatibility isn't much of an issue.

Static methods do not have access to other variables. If the variable was defined as self::db you could use it then, and you might want to instantiate it that way to do it.

Static methods are best for things that don't require objects, such as formatting text, redirecting pages, etc.

Kerry