deansatch Posted December 1, 2008 Share Posted December 1, 2008 I have been using php for a long time now and I am know it very well. I feel it is time I learned OOP though. I have been reading up on it and if I understand correctly, it allows total separation of html and php backend stuff. I am however having trouble finding examples or tutorials that show OOP in a real world useful way. e.g. I have a simple while loop output in to a table which I currently do like this: $v_list ="<h2>Variable List</h2>\n <div><table><thead><tr><td>V 1</td><td>V 2</td><td>V 3</td></tr></thead><tbody>\n"; $query = mysql_query("SELECT * from table"); $vnum=0; $vnum = mysql_num_rows($query); while($row = mysql_fetch_assoc($query)){; $v1= $row['v1']; $v2= $row['v2']; $v3= $row['v3']; $v_list .= "<tr><td>$v1</td><td>$v2</td><td>$v3</td></tr>\n"; } $v_list .= "</tbody></table></div>"; if($vnum> 0){echo $v_list;} How could I use OOP to keep the php part in a separate file from the html? e.g. file 1: my php code looping and setting of variables file 2: <h2>Variable List</h2> <div> <table> <thead> <tr><td>V 1</td><td>V 2</td><td>V 3</td></tr></thead><tbody> <tr><td>$v1[0]</td><td>$v2[0]</td><td>$v3[0]</td></tr> <tr><td>$v1[1]</td><td>$v2[1]</td><td>$v3[1]</td></tr> <tr><td>$v1[2]</td><td>$v2[2]</td><td>$v3[2]</td></tr> </tbody> </table> </div> Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/134988-learning-oop/ Share on other sites More sharing options...
trq Posted December 1, 2008 Share Posted December 1, 2008 it allows total separation of html and php backend stuff. While OOP can assist in this area, its far from its main objective, so I think you may have been given a bum steer there. If you want to learn OOP, I would suggest picking up one of the bigger frameworks and building a few projects with it. These usually impliment a few different design patterns including MVC. Zend Framework is pretty darn popular atm. Quote Link to comment https://forums.phpfreaks.com/topic/134988-learning-oop/#findComment-702999 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.