Click to See Complete Forum and Search --> : mix and match?


Sid3335
07-14-2006, 08:46 AM
I've noticed that some people mix and match php and html. and some write entirely in php and echo/print the html elements.

are there benefits to either method? which is the prefered (industry standard) method.

Thanks guys

PineSolPirate
07-14-2006, 11:09 AM
I've done it both ways, but I prefer to mix and match. Otherwise you might as well user perl or python or something. I think the mix and match is one of the best strengths of php.

aaronbdavis
07-14-2006, 12:40 PM
mix and match is fine for small scripts. Most of my site is written that way. However, when you have a larger site, or at least larger scripts, most people will separate the presentation (i.e. HTML) from business logic (i.e. PHP) using some sort of template engine like Smarty (http://smarty.php.net). In the long run, it make scripts much easier to maintain. People have also been talking alot about MVC frameworks which, from what I have read, make things much easier than a simple template engine.

PineSolPirate
07-14-2006, 02:58 PM
Amen to smarty. Thats the coolest thing ever for letting coders and design people work together. I'm actually re-coding my site in it right now. As far as MVC frameworks, do you know any good ones? I was looking at some based on model2 but everything seems so poorly documented.

NogDog
07-14-2006, 06:29 PM
I'm flexible to some degree, but I don't like having to read code that goes back and forth repeatedly. Sometimes I end up using echo with heredoc syntax to output a chunk of plain HTML rather than jumping out of PHP mode. Maybe it's because most of my first experiences with web programming were in Perl?

Now that I'm trying to do more with object-oriented PHP, I find myself putting chunks of HTML into methods, so that the overall program logic isn't interrupted by chunks of HTML, but instead by method calls such as $this->printDocHead(); or $this->printNavigation();.

PineSolPirate
07-15-2006, 03:10 AM
Before I started using smarty I usually had a header and footer include, which helped clean things up. Nav includes are handy too.