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.

I would like to set up a table prefix for all my models, How can set config.php

Regarding my configuration prefix; how to use it?

I would like to set up a table prefix for all my models, since this is how it is designed in the database.

  • How can I achieve that?
  • How can set it in config.php
  • How can I use in Model
class Users extends Phalcon\Mvc\Model
    public function getSource()
        //return 'ik_' . 'users';
        return $this->get('config')->database->prefix.'users';
//config.php    'prefix'   => 'ik_'
return new \Phalcon\Config(
    'database' => array(
        'adapter'  => 'mysql',
        'host'     => 'localhost',
         'username' => 'root',
        'password' => '',
        'name'     => 'ikphp',
        'prefix'   => 'ik_', // table prefix


Set the configuration in the DI:

$di->set('config', $config);

This is the config: https://github.com/phalcon/forum/blob/master/app/config/config.example.php

And this is where the config is set as service: https://github.com/phalcon/forum/blob/master/app/config/services.php#L200

This way you can access the configuration in the models.

edited Jul '14

Thank you