What is a good way to remove the code from display pages when developing with PHP. Often the pages I work on need to be editted by an outside person. This person is often confused by lots of blocks of PHP, and also likes to break my code.
I've tried moving blocks of code out into functions, so now there are functions spread out all throughout the HTML now. As some pages become more complex it becomes a program again, and processing POSTs are questionable.
What can I be doing better in my PHP development?
It's versatile: One of the major benefits of PHP is that it is platform independent, meaning it can be used on Mac OS, Windows, Linux and supports most web browsers. It also supports all the major web servers, making it easy to deploy on different systems and platforms at minimal additional cost.
PHP is much faster than other options (such as ASP) because of its faster load time as a result of its own memory space that removes most of the overhead in execution.
You don't need a "system" to do templating. You can do it on your own by keeping presentation & logic separate. This way the designer can screw up the display, but not the logic behind it.
Here's a simple example:
<?php
$people = array('derek','joel','jeff');
$people[0] = 'martin'; // all your logic goes here
include 'templates/people.php';
?>
Now here's the people.php file (which you give your designer):
<html>
<body>
<?php foreach($people as $name):?>
<b>Person:</b> <?=$name?> <br />
<?php endforeach;?>
</body>
</html>
Take a look at how some of the popular PHP frameworks use templating. Examples include cakePHP, Zend Framework, and Code Igniter. Even if you are not going to base your site on these frameworks, the template design pattern is a good way to keep php code away from your web designers, so they can focus on layout and not functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With