We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.8k
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));
    }
}