logo       

Tight coupling in Model with Zend_Db: msg#00020

Subject: Tight coupling in Model with Zend_Db
Hi all,
 
first of all, I'd have to say that the Zend_Db component is really hot!! I've been using it with pleasure and succes.
 
However, there is one thing I am reluctant about. From 9AM to 5PM, I am a Java developer, but I devote my free time to PHP. I can see some areas where Java is more mature, and I beleive we (as PHP developers) should learn from this.
 
I strongly beleive that the Model part of MVC should not be aware of any database handling. It should be the other way round. The Model shouldn't really change if another DB is adopted. Maybe I am missing something in the Zend_DB component... if that's the case, please let me know!
 
I've developed (read: put together in a quick and dirty way, for now) a few classes that are able to map (using XMl config files, Hibernate style) Model objects to database tables. The code to use it looks like this:
$dbManager = new  Some_Package_DbManager($zend_db_adapter);
$modelObject = $dbManager->load("Some_Model_Class", "someIdValue");
this modelObject isn't an actual class, but it is a proxy with that class as target. This proxy handles all the lazy initialization (if configured in the XML file).
 
I beleive a structure like this helps decoupling the Model from the actual DB system used. Of course, this Db Manager (or whatever it should be called) uses most of the Zend_Db features already available.
 
Do you guys share my opinion? Do you think this could be an interesting feature for Zend_Db?
 
With regards,
 
Allard Buijze
<Prev in Thread] Current Thread [Next in Thread>