how to call a static method in a custom magento class
I have a custom model in a custom Magento model with a static function:
class ABC_Module_Model_ClassN开发者_如何学编程ame
{
static public function send ( $something)
{
// do something static
}
}
Now I call the function like this:
ABC_Module_Model_ClassName::send($something); // works and is nothing wrong with it
More for consistency purposes, I would like to know if Mage has an internal way of calling static methods, something like this:
Mage::getModel('abc/module_className')::send($something); // this is wrong
// or
Mage::getModel('abc/module_className', send($something)); // with a callback or something
Given that any method like Mage::getModel()
will actually return an instance of the class, you'll be calling it dynamically rather than statically. E.g you'd be doing $module->staticMethod();
instead of Module::staticMethod().
.
So your best best is to
- either put the static method as a regular function so it'll be available globally,
- put all your static methods in one class and name the class something like
Common
so you won't have to type the really long name, - or just call it statically the way you've done in your question e.g
Module::method()
.
In the end, the only way to call a method statically is via Class::method()
.
精彩评论