Re: Separate PHP Code From HTML || Pros & Cons?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hey all.

I've built a simple, yet effective PHP based CMS, one that I use in all 
sites I develop.

Unfortunately, from site-to-site, functionality may be different; i.e. I 
often have to extend the original CMS to account for custom client needs, 
which means grabbing the most recent version of my CMS, and hacking it to 
address whatever customization is required.

This presents problems in that any updates I make to the CMS only affect the 
site I'm working on.  So, while working on one site I may make changes to 
the CMS, changes that improve the app., but other older sites do not get 
updated -- it's OK now, but things are getting sloppy ;--)

I would dearly love to have a base CMS repository that all sites would draw 
on, extending the base CMS in the event that a particular client has need of 
customization.  Some combo of Linux and Apache would do the trick; e.g. PHP 
requests for any of my sites would point to say, "/home/cms/includes/"

That would help (not solve) the version control problems I'm running into 
now (still have to figure out how to extend the CMS for customization).

Now, the other issue I'd like to address is separating PHP code logic from 
site HTML.

I've restructured my CMS classes to do all MySQL queries, code logic, etc. 
prior to calling target HTML template.  This is great in that now when an 
error occurs, I can catch { throw new Exception($e) } and gracefully display 
the error along with a means to repopulating the offending form page.

I've often heard the mantra, "separate code from HTML", but it seems 
ridiculous at times to include tiny HTML snippets that can easily be echoed 
out, or stored in a variable.  Smarty goes to the extreme in separating code 
from HTML, but looking at their templating system, I wonder what's the 
point?  Is it the end of the world if you've got a few choice if, then, else 
statements in your HTML templates?

I'm thinking of creating a bunch of include files based on request type in 
my CMS Admin Center; e.g. include "classes/admin/news/add.php", where add, 
update, or delete is the request type.  This cleans up my PHP processing 
pages quite a bit (don't have all the if add, do X, elseif update, do Y, 
etc. logic to comb through).

Last thing to do is write up a generic form builder class to assemble my 
form pages, but that may be more work than necessary -- K-rist, webwork is 
messy business ;--)

Clues, Opinions, etc. are welcome.

TIA,

--Noah


 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux