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

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



10.5k
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);


2.0k

Think you for your answer