|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How Do I Separate The PHP From The HTML?
Below is an excerpt from a PHP script that I have been using. The entire script is kind of large and
cumbersome. This one portion of the script is long horizontally and goes off the screen to the right. I am at a point in my programming career that I need to begin using "classes" and "templates" so I figure that this is a good place to start. I've got the general idea about how PHP object oriented programming works. It's just the details for which I need more of a grasp. Can anyone give me any ideas about how I can separate the HTML from the PHP in the below script? In other words, I need a template for the HTML, a class for the PHP/MySQL database extraction function, and an instance to call the whole thing. I would appreciate any pointers about how I might get started. PHP Code:
Thanking you in advance. Volitics |
|
#2
|
|||
|
|||
|
My personal suggestion on this one is to start separating php from html by dropping in and out of php so you're not echoing html. This goes a long way to avoid very long echo statements especially when there are large blocks of html.
Some people dislike this way of doing things though so I also recommend trying out other suggestions if people have them. |
|
#3
|
||||
|
||||
|
You might consider writing (or finding) a table generation class that'll help you keep from having to print all those cumbersome table rows and cells. As a temporary quick and dirty fix, I once wrote a table() function that took an array of arrays as an argument. Each array defines a row and its elements define table cells. It doesn't take much to split all that out and write a basic table that you've had to pass nothing but data to. Of course, with that approach, you're fairly limited in what you can do with the formatting. For my purposes, it worked fine, as I had a series of standardized tables I need to print out, and this saved me some trouble.
There are a number of template engines and classes out there already that you might look into. I don't know any references off hand (Slappy, maybe?), but it shouldn't take much digging for you to find something you can work with or learn from. |
|
#4
|
|||
|
|||
|
kode_monkey, dhouston.
Thank you for the help. Best Regards, Volitics |
|
#5
|
|||
|
|||
|
Volitics,
You may want to look into templating systems... There are quite a few of them... Smarty being the most popular (from what I've seen). There's also patTemplate (which I find to have an easy learning curve)... There's an article written by Havard (Lindset) on getting started with patTemplate... You should have a look. It will have you up in moments time.
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#6
|
|||
|
|||
|
There is a thread simular to this one here ( http://forums.devshed.com/t71738/s.html ) with a good learning experience.
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > How Do I Separate The PHP From The HTML? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|