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 use the table prefix to code a project in phalcon?

How to use the table prefix to code a project in phalcon?



15.2k
Accepted
answer

One way to acomplish this is to include the table prefix within your config object. For each model that you define, you will also need the set the source so that the table prefix is applied.

config.php

return new \Phalcon\Config(array(
    'db' => array(
        'tblPrefix' => 'xyz_'
    )
));
Robot Model
class Robots extends \Phalcon\Mvc\Collection
{
    public function getSource()
    {
        $source = $this->getDi()->getConfig()->db->tblPrefix . 'robots';
        return $source;
    }
}

services.php

$config = include APPLICATION_PATH . '/config/config.php';
$di->set('config', $config);


3.2k

Think you for your answer