We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to specify table-class mapping in Models

FooBar model is mapped to foo_bar table. But I don't follow this this convention. The name of my tables are the lowercase of Model names. I tried to create a base class for moldels as follows:

class BaseModel extends Phalcon\Mvc\Model
{
    public function getSource()
    {
        return strtolower(get_class());
    }
}

But this does not work because get_class() return thne name of parent class (BaseModle) for all extended models. What is the correct solution?



5.2k
Accepted
answer


98.9k
edited Jul '14

You have to pass $this to get_class():

class BaseModel extends Phalcon\Mvc\Model
{
    public function getSource()
    {
        return strtolower(get_class($this));
    }
}