Zend Framework - Database Table Singleton
Posted
by Sonny
on Stack Overflow
See other posts from Stack Overflow
or by Sonny
Published on 2010-04-14T21:57:58Z
Indexed on
2010/04/14
22:03 UTC
Read the original article
Hit count: 275
I have found myself doing this in my code to 'cache' the work done when instantiating my Zend_Db_Table
models:
if (Zend_Registry::isRegistered('x_table')) {
$x_table = Zend_Registry::get('x_table');
} else {
$x_table = new Default_Model_DbTable_X;
Zend_Registry::set('x_table', $x_table);
}
It bothered me that this method isn't very DRY and it dawned on me today that a singleton pattern would probably be a better way to do this. Problem is, I've never written a singleton class. When I did some web searches, I found some offhand comments about Zend_Db_Table
singletons, but no real examples.
I already have meta-data caching configured.
- How do I make my
Zend_Db_Table
models singletons? - Are there pitfalls or downsides?
© Stack Overflow or respective owner