Jump to content

Recommended Posts

Hey guys - i've been using PHP for 3 years - now i'm working on a website and I want to develop it in OOP - I've written a fully blown - and pretty advanced CMS in suquential code.

 

I've got my head round writing PHP in OOP but on my site I've a couple of areas that I don't think needs OOP'd(?) - such as selecting lists of information. For these areas how would I write the code - as putting lists for navigation in as objects I think is overkill.

 

Any and all ideas taken on board!

Link to comment
https://forums.phpfreaks.com/topic/137940-solved-oop-question/
Share on other sites

  • 2 weeks later...

You might consider the "Model-View-Controller" architecture. In php most MVC frameworks load a template type file which contains purely procedural code (or tags). See http://www.smarty.net/crashcourse.php and take a look at how cakePHP and CodeIgniter handle views.

 

~ Christopher

Link to comment
https://forums.phpfreaks.com/topic/137940-solved-oop-question/#findComment-727588
Share on other sites

I would suggest thinking of your code and what it actually does, then split it down to different classes and functions....

 

eg in a cart project you would have;

 

A Product Class would contains methods to deal with naming and pricing.

 

extending the Product class to do deal Books, DVD's or Clothing. each putting forth their own methods, with parent class Products....

 

I would also suggest starting with the directory layout, and then coding the essential/core pieces of your project like the db connections, file handling...ect....im currently working on a project of my own....converting an existing procedural coded site to OOP... :-)

Link to comment
https://forums.phpfreaks.com/topic/137940-solved-oop-question/#findComment-727633
Share on other sites

I would also suggest using a MVC framework and then deal with elements of your site on a case by case base.  Anything i build uses a custom MVC framework i have built which has a very small overhead for loading controllers and views.  The model portion of my framework(usually some sort of ORM system that connects to a database) is the real bottle neck of the system(and should be for most MVC Frameworks) so there are case when i will use straight queries instead of the models.  The most common example of something that might be in a database and i would not use a model for is navigation since most navigation is on multiple pages.  Most other things i would only usually need a few dozen models(and if not it would be paginated data.

Link to comment
https://forums.phpfreaks.com/topic/137940-solved-oop-question/#findComment-730982
Share on other sites

  • 5 weeks later...
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.