Zend Framework Source Code Snippets

How to set table prefix with Zend_Db_Table

Bookmark and Share
1
 
1
2
/* bootstrap file */
define('_TABLE_PREFIX', $config->db->table->prefix);
1
2
3
4
56
7
8
9
1011
12
13
14
class Extend_Db_Table extends Zend_Db_Table_Abstract
{
     /**
     * This will automatically set table name with prefix from bootstrap file
     * @return void     */
     protected function _setupTableName()
     {
         parent::_setupTableName(); 
         if(defined('_TABLE_PREFIX')) {             $this->_name = _TABLE_PREFIX . $this->_name;
         }
     }
}

Comments

nicolae-serban nicolae-serban
1 year ago

very nice
Thanks

Neantis Neantis
1 year ago

Great snippet!

You can do even better by using the configuration you have previously registered in Zend_Registry. It removes the need for the constant _TABLE_PREFIX, and I think it is a bit more elegant.

Pacek Pacek
1 year ago

@Neantis: you are right, that is more elegant ;). More "Zendy".

You must login before commenting on a snippet. If you do not have an account, please register.

Snippet description

Snippet details

Created:
Pacek Pacek
1 year ago
Edited:
Pacek Pacek
1 year ago
Revision Id:
13
Edit Message:
Initial Release
Tags:
zend_db Zend_Db_Table table prefix
Comments:
3
Views:
196
Points:
0 (0 votes)

History

r13

Initial Release

Pacek Pacek
1 year ago