Page 1 of 1
PHP before or embedded into HTML
Posted: Fri Jul 28, 2006 3:05 am
by SimonJ621
Hello,
A simple design question. I'm rather new to PHP and was wondering if there was a 'best practice' for placing PHP code in a document. Is it better to start with PHP or start with HTML and then initiate php within the html?
Thanks,
Jason
Posted: Fri Jul 28, 2006 3:07 am
by JayBird
Either really.
But it is usually best to keep your code separate from the design/layout depening on the application.
You could look into templating engines
Posted: Fri Jul 28, 2006 3:24 am
by SimonJ621
I'm not that familiar with templating engines other than reading a little bit on SMARTY. But if I remember correctly, the design documents are seperate from the coding documents, much like CSS? So if that's the case, putting PHP inside the <body> tag doesn't mean you're mixing coding and design aspects? Or am I just wrong

?
Thanks for the quick reply,
Jason
Posted: Fri Jul 28, 2006 10:46 am
by daedalus__
I honestly don't think that you should worry about it until you know more about PHP.
Stick to making pages that work and keep reading.
Posted: Fri Jul 28, 2006 11:28 am
by alvinphp
Best practice would be to seperate your html and php as much as possible. However, your html will need some PHP like loop and conditional statements.
Posted: Fri Jul 28, 2006 1:27 pm
by feyd
I would also interject that learning to do it the "correct" way early on will save you from trouble getting out of a bad learned habit later.
Correct in this sense is to separate business and presentation logics as has been already said.
Posted: Fri Jul 28, 2006 1:33 pm
by RobertGonzalez
Daedalus- wrote:I honestly don't think that you should worry about it until you know more about PHP.
Stick to making pages that work and keep reading.
Learn properly the first time and you don't have to learn a second time.
============================================================
Today's wisdom brought to you by the nice lady at the taco truck where I got my breakfast burrito.
============================================================
Programming logic is the code that tells your apps what to do. Display logic tells your pages what to show. You can mix the in PHP, but it makes it really tough later on down the road for you (or other developers) to change your design and/or presentation logic unless there is significant documentation or very sensible code-flow.
My first few apps were like that, all mixed up like speghetti and peanut butter. Then I got ahold of templating and it got better. Then I began using Template Lite (a fork of Smarty) and my apps fly and are easy to edit/maintain.
My suggestion, to reiterate was has already been stated a few times, is to develop a good practice now so as you grow in your development expertise you don't have to relearn something else later.
Posted: Sat Jul 29, 2006 10:35 am
by SimonJ621
Thank you for all the replies. The PHP community is one of the reasons I was drawn to it in the first place, and it's great to see such support. And hopefully I'll learn it well the first time. Right now I'm reading two books, Beginning PHP and MySQL: From Novice to Professional from Apress by Jason Gilmore and Essential PHP Security from O'Reilly by Chris Shiflett. Hopefully these are good sources.
Thanks again,
Jason
Posted: Sat Jul 29, 2006 2:10 pm
by feyd
Shiflett frequents these forums, and yes, the book is a good resource.