Iv been working on a couple of projects lately that require centralized programming. This is a term iv made up but i think it explains exactly what i mean…. more or less.. to other programmers/geeks…
It is generally the art (?) of programming in such a way that multiple sites, or multiple parts of a single site can all (re)use many of the same files stored in a central location. This way if you need to update something you only need to do it in 1 file instead of many.
Some tricks iv been using to do this:
Apache's URL rewrite
Nice little option in .htaccess files that allows you to display the contents of file X for the url Y that the user entered. Typically this is used for SEO friendly URLS. like instead of "domain.com/index.php?page=webshop&category=hats&type=tophat&id=1" you can have "domain.com/webshop/hats/tophat/1.html" which looks much prettier to google. The kind of url they would actually ask out on a date when not drunk. Now the user sees the second link but the server is actually tricked into sending the first link. So you can program in the old-fashioned easy to do way with a pile of get variables and it still all looks pretty. This fits into my centralised programming scheme because you only have 1 index.php file that is dishing out all the data but you can still provide many links and pages.
Linux mount –bind
This one took me a little longer to get but it is fantastic in its use (i cracked it just yesterday actually). Essentially it is like a shortcut in windows but not quite. You bind directory X to directory Y. Then when you go into directory Y you see the contents of directory X. Fantastic :D. Why is this useful?? well for php includes its not really as usually you can just use the full address so it doesn't really matter where they are. However for html js/img includes you need to have a directory that is under the domain. So we make an empty img directory under the domain account, bind the centralised img directory to it and hey presto domain.com/img is showing all the centralised images :D.
And the fun stuff, the part i cracked yesterday, with a little tweaking of the sudoer file in Linux you can mount directories from php on the fly. In my case i needed to be able to add accounts from an admin system, create a directory for the account, and mount an img directory in the account directory
good stuff!
Templates!
This is an important part in centralised programming. Using templates for the design part. I recently made a very nice little template engine sporting several nice options (all specific to the project I'm working on). Templates remove the design element from your programming and also make it easier to add multiple designs to a project quite easily.
well that's enough for now, gotta get back to work ![]()
Comments