[eluser]stormbytes[/eluser]
I'm writing a static function that checks if its argument, $url, already exists in the database. The static function is a method of the Asset_model, and looks something like this (only a static version):
Code:
Class Asset_model Extends Model()
{
function asset_dupecheck($url)
{
$this->db->select('asset_id, catalog_title, asset_title')->where('asset_url', $url);
$row = $this->db->get('Assets')->row();
return $row;
}
}
$this in the above-code is meant to illustrate my objective. In fact, that's my problem, since I can't use $this within a static method.
So I ask:
1. What's the correct way to structure the code within the asset_dupecheck() function, so that it can access the db method of it's container-class? I know it has to reference 'self' in some way, but I'm not sure about the syntax and google's not my friend.
2. My understanding was that :: is used to access a static property or method by referring to the class as a whole.
eg. MyClass::myStaticMethod()
Why then, does this also work with ordinary methods?
eg. I create a regular method for say.. a model class. But then, I can call that method from within a Controller using Model_Name::Method_Name() same as $this->model_name->method_name()?
and 3.
If (2) Then what's the point of a static method altogether if I can use *any* class method, static or otherwise, but simply calling it on the Class like MyClass::myMethod() ?
Thanks for lookin!