Wednesday, 15 January 2014

php - Master / Slave switch in the Zend Framework application layer -


I am writing an application for which the Master / Slave switch is required inside the application layer as I am now Instruct a Zend_Db_Table object on the mapper's creation, and then set the slave default adapter.

Now inside the base mapper clas, I have the following method:

  Public function utilityWit adapter () {if (Zend_Db_Table_Abstract :: getDefaultAdapter ()! = $ This- & Gt; _writeDb) {Zend_Db_Table_Abstract :: setDefaultAdapter ($ this-> _writeDb); $ This- & gt; _table gateway = new Zend_Db_Table ($ this-> _tableName); }}  

I need a prudent inquiry on this. I do not think the upper part is too much, I suspect that there should be a better way.

A type of object Zend_Db_Table_Row_Abstract misses which table object's output was done. But you can change the related table before calling save () .

  $ readDb = Zend_Db :: factory (...); // slave $ writeDb = Zend_Db :: Factory (...); // Master Zend_Db_Table :: setDefaultAdapter ($ readDb); $ MyReadTable = New MyTable (); // Use default adapter $ myWriteTable = new MyTable ($ writeDb); $ Line = $ myTable-> Search (1234) - & gt; Present (); $ Line-> Column1 = 'value'; $ Row-> Settable ($ myWriteTable); $ Row-> Save ();  

No comments:

Post a Comment