Jump to content

Guidance on OOP practice


pavsid

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.