Other than standard OO concepts, what are some other strategies that allow for producing good, clean PHP code when a framework is not being used?
If you didn't start with a framework, you'd end up building one yourself. But today, thanks to all the autoloading and interoperability work done by PHP-FIG, building without a framework doesn't mean building it all by yourself. There are so many excellent, interoperable packages from a wide range of vendors.
In other words, PHP frameworks help to promote rapid application development (RAD), which saves you time, helps build more stable applications, and reduces the amount of repetitive coding for developers.
CodeIgniter is the top choice for a beginner-friendly PHP framework that is easy to use and quick to learn. It works on the MVC architecture, is easy to install, offers several guides and is easy to understand for beginners to get started with developing web applications on PHP.
Pros of Zend/Laminas It's also the most used PHP framework by enterprises. Zend follows the PHP Framework Interop Group (PHP-FIG) standards, meaning that its code can be ported across to other frameworks without difficulty. Like Symfony, you can use just the components you need. You can use Zend to build RESTful APIs.
Remember: MVC, OOP and tiers are design concepts, not language constructs, nor file-structuring.
For me, this means that when not using a framework, and when there's not different teams for programming and designing; there's no value in using another template system on top of PHP (which is a template language). Also, separating code from layout doesn't necessarily mean doing it on different files.
This is how i used to do for one-off, seldom expanded, PHP web apps:
that's your 'framework', then you write the 'presentation' layer:
one PHP file for each page, starts with some simple code to fetch the objects needed, followed by HTML with interspeced PHP code, just to 'fill in the holes'. with very few exceptions, the most complex code there should be for loops. I make a rule to use only one-liners, the ?>
should be in the same line as the opening <?php
and that's it. If working alone, it has all the separation of intents you need, without drowning in a lot of files for a single user action. Each page as seen by the user is managed by a single PHP file.
It's even easy to maintain, after a few months without looking at the code, since it's easy to test the app, taking note of the filenames in the URL field of the browser. This guides you directly to the relevant code.
(nowadays, of course, i'm using Django for almost everything...)
If you ever find yourself mixing HTML and code, just STOP. You're, well... You're doing it wrong! http://dennisjudd.com/albums/cute_cats/wrong_mike.jpg
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