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?



3.6k
Accepted
answer


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