Click here to Skip to main content
15,917,795 members
Home / Discussions / Web Development
   

Web Development

 
QuestionPHP Best Practices - Decomposition Pin
User 1218466519-Apr-16 2:54
User 1218466519-Apr-16 2:54 
Hello all,

PHP was one of the first programming languages I learned. However, during this phase, I was not really introduced to OOP in PHP or, honestly, many good practices. Now that I have experience with heavily OOP languages such as Java and C#, I have to say, my previous PHP, while functional, was a bit of a mess. As I am now working on a new project that will be using PHP (an eCommerce one), I would like to do it right from the start.

So (my apologies for the long introduction) here is my real question - how would you recommend separating presentation from logic?

I have a a custom class that handles access and database queries, and will be working on another to represent an item. How would y'all recommend 'presenting' this data to the user? I have a function within my database access class that retrieves the necessary data (either a list of items by category or details for a specific item), but would you advise writing a method within the database access class that uses "echo/print" to display the HTML (and all you would have to do is call the appropriate method of the class instance within the main HTML/PHP page), OR, would you advise, within the main "View" page to simply call the method that just retrieves the necessary data and then write the PHP code necessary to display the data (such as a for loop to print out all the items for a specific category) within the "display" page itself.

I apologize if my question is not clear. I realize either way will work, but I am curious what others consider a good practice.

Thanks!

modified 19-Nov-20 21:01pm.

Questioni am beginner in webs how can i make this blogger theme SEO and Google friendly? Pin
Chat4Enjoy18-Apr-16 21:27
professionalChat4Enjoy18-Apr-16 21:27 
RantRe: i am beginner in webs how can i make this blogger theme SEO and Google friendly? Pin
Richard Deeming19-Apr-16 2:07
mveRichard Deeming19-Apr-16 2:07 
RantBest practice for html5 design Pin
Jassim Rahma17-Apr-16 12:15
Jassim Rahma17-Apr-16 12:15 
GeneralRe: Best practice for html5 design Pin
Nathan Minier18-Apr-16 3:38
professionalNathan Minier18-Apr-16 3:38 
Questionprint 1 to 100 using a php code with the following instructions: Pin
Kelvin Ng'ethe13-Apr-16 5:19
Kelvin Ng'ethe13-Apr-16 5:19 
AnswerRe: print 1 to 100 using a php code with the following instructions: Pin
Richard MacCutchan13-Apr-16 20:48
mveRichard MacCutchan13-Apr-16 20:48 
GeneralRe: print 1 to 100 using a php code with the following instructions: Pin
Peter_in_278013-Apr-16 20:56
professionalPeter_in_278013-Apr-16 20:56 
AnswerRe: print 1 to 100 using a php code with the following instructions: Pin
ZurdoDev25-Apr-16 1:42
professionalZurdoDev25-Apr-16 1:42 
QuestionAngularJS and page bookmarking Pin
Member 179509711-Apr-16 23:06
Member 179509711-Apr-16 23:06 
AnswerRe: AngularJS and page bookmarking Pin
Nathan Minier14-Apr-16 3:10
professionalNathan Minier14-Apr-16 3:10 
Questionrun vb.net web app in browser that has enough room Pin
dcof11-Apr-16 17:55
dcof11-Apr-16 17:55 
AnswerRe: run vb.net web app in browser that has enough room Pin
Richard MacCutchan11-Apr-16 21:35
mveRichard MacCutchan11-Apr-16 21:35 
QuestionmaxTimeout setting in Machine.config file Pin
Prasanth P1-Apr-16 15:16
Prasanth P1-Apr-16 15:16 
QuestionPHP - Warning: fopen(): Filename cannot be empty Pin
M Riaz Bashir29-Mar-16 22:15
M Riaz Bashir29-Mar-16 22:15 
AnswerRe: PHP - Warning: fopen(): Filename cannot be empty Pin
Jochen Arndt29-Mar-16 22:38
professionalJochen Arndt29-Mar-16 22:38 
GeneralRe: PHP - Warning: fopen(): Filename cannot be empty Pin
M Riaz Bashir30-Mar-16 0:06
M Riaz Bashir30-Mar-16 0:06 
AnswerRe: PHP - Warning: fopen(): Filename cannot be empty Pin
W Balboos, GHB11-Apr-16 5:30
W Balboos, GHB11-Apr-16 5:30 
QuestionAccess Denied issue for Web service Pin
Prasanth P27-Mar-16 0:07
Prasanth P27-Mar-16 0:07 
AnswerRe: Access Denied issue for Web service Pin
Afzaal Ahmad Zeeshan28-Mar-16 9:48
professionalAfzaal Ahmad Zeeshan28-Mar-16 9:48 
QuestionHow to sync database offline and online application Pin
Arvind Zamakia25-Mar-16 22:17
Arvind Zamakia25-Mar-16 22:17 
AnswerRe: How to sync database offline and online application Pin
ZurdoDev28-Mar-16 8:37
professionalZurdoDev28-Mar-16 8:37 
AnswerRe: How to sync database offline and online application Pin
Afzaal Ahmad Zeeshan28-Mar-16 9:50
professionalAfzaal Ahmad Zeeshan28-Mar-16 9:50 
QuestionUnitOfWork And Repository Patterns Not Needed When Using EF Pin
MadDashCoder24-Mar-16 8:34
MadDashCoder24-Mar-16 8:34 
AnswerRe: UnitOfWork And Repository Patterns Not Needed When Using EF Pin
Richard Deeming24-Mar-16 9:13
mveRichard Deeming24-Mar-16 9:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.