How can I write php codes independent from XHTML codes? Thanks in advance
+1
A:
Use a PHP framework like cakePHP or Zend.
or create a custom solution and use template engine like Smarty for separating your code logic with design.
Gaurav Sharma
2010-03-17 12:27:21
Don't use Smarty. PHP is a fine templating language in it's own right. Why complicate it with another language on top of it?
fireeyedboy
2010-03-17 12:35:31
A:
Or you can separate logic from markup only with pure php, which is in fact a good templating language.
Before doing MVC, an approach was to put code on separate classes, getting results needed on top of page and only using variables to echo or loop them inside html markup. You can use the same pattern to included portions of xhtml, the separations of concerns is then moved to pure code files and classes design.
But as we are 2010 I definitely vote for using MVC, even for very small project, with or without a framework.
Benoit
2010-03-17 13:18:19
@Benoit actually I find the approach you gave for before 2010 fully sufficient for small sites. What for would I need MVC when all I want to do is put up some (semi-)static pages and maybe a contact form? Separating C and V is a definitely a must, but that can be done in the same file and it's not always necessary to separate the M from the VC when your app barely contains any domain logic. Don't get me wrong, MVC is great and helps tackle complexity *when that is needed*, but when not, it's just bloat. It's just a matter of when to use which pattern.
Gordon
2010-03-19 09:37:22
ok, I think i'm too regular with MVC frameworks to think to this, but it may be a good approach as long as no database interaction is required.
Benoit
2010-03-19 12:17:14