pavsid Posted July 31, 2011 Share Posted July 31, 2011 Hi, I'm writing a mini CMS built on Zend Framework, and whilst I should already know this, for some reason I've never got to the bottom of it and reasearched which is the best practice. It's a common issue - you have a form to create a post, or a page, or whatever - and you want to store that data in the database. Now at some point that data will be pulled back out the database and used in the application, whether to populate the form again to allow changes to be made, or to display as intended on the front-end of the site. In either direction i'll have a 'page' object which stores all the necessary data - my question is what is the best practice for transferring the data from the object, to the database, and visa versa? I'll have a separate 'adapter' class which will sit between the object and the database, but how should the data be passed to it? I have two options so far - first is to store the adapter inside the 'page' object and call a method such as $page->save() which will in turn use the adapter to save the properties of the object to the database, or secondly, i could instantiate the adapter separately and pass it the 'page' object, like, $adapter->savePage($page). I'm sure there are many other ways to do it, but what's the best? Appreciate any help. Quote Link to comment https://forums.phpfreaks.com/topic/243408-guidance-on-oop-practice/ Share on other sites More sharing options...
gizmola Posted July 31, 2011 Share Posted July 31, 2011 This is part of using the MVC. Your code that handles data should be in the model classes. Many people also utilize an Object relational mapper (ORM) class. The two best known PHP ORM's are propel and doctrine. It is possible to integrate either one with zend framework. I'm sure if you google Zend Framework Doctrine you'll find a number of tutorials and examples. Quote Link to comment https://forums.phpfreaks.com/topic/243408-guidance-on-oop-practice/#findComment-1249928 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.