I find that I’ve been doing my php-html interfaces wrong all these years. What I’ve been doing is encapsulating my html in an htmlentities string and embedding that within my php script rather than embeddiing my php snippets in the html. I also parse my forms and validations as a separate php file. As such, my “sticky form” code, among others, is pretty ugly.
Guess such things are to be expected when you’re self taught in isolation. I’d appreciate your advice on how to change my design approach given this recently gained literacy.
All of the screens and forms in this project are embedded in a three column layout where all but the center column and page heading remain the same. Much of the center column also remains the same, differing mainly in the input fields on forms and database field and content on data display pages.
My current strategy is to encapsulate the three column html and common center-column logic in an abstract class. Then generate children for each of the unique pages by extending the abstract class and functions. (And, as mentioned, the forms’ “action” reference separate parse/validation php files – also children of an abstract parse/validation class.)
However, with my new found knowledge of embedding the php within the html rather than vice versa, I don’t understand how to encapsulate the three column html in the root class without using htmlentities.
What am I missing?
Your in the same boat i was in 5 yrs ago
http://www.youtube.com/playlist?list=PL75B9D91CD69ED950 you can learn a few new tricks from this guy.
I also recommend reading From Flat PHP to Symfony2. “You’ll write a simple application in flat PHP, and then refactor it to be more organized. You’ll travel through time, seeing the decisions behind why web development has evolved over the past several years to where it is now.”
Just as a caution to others who might want to visit these tutorials –
– you need to be reasonably familiar with OOP concepts already as, IMO, this tutorial series focuses solely on syntax: “how” to code OOP concepts in PHP, (not the “why” or the concepts themselves) The same holds for his tutorials on patterns and MVC.
– the interface tutorial is worth skipping entirely. Even he admits to rarely using it – and it shows. (To digress: he doesn’t mention that, whereas you can only extend one class in PHP (inheritance) you can include many interfaces into a class. Many GoF patterns do use this interface capability.)
– he chose not to clean up his tutorials, so you will have to sit through a number of stumbles, retraces and debugs
With those caveats, the link does indeed contain a few tricks.
The very first page in this tutorial addressed my confusion. Thank you very, very much.
My confusion? Hard to explain. Learning that standard practice is to embed php statements within the html, I didn’t think I could use a php include for html that itself had embedded php.
The second example in the link you provided shows exactly that scenario.
The HTML code is now stored in a separate file (templates/list.php), which is primarily an HTML file that uses a template-like PHP syntax:
So I am not as far off course as I thought.
Thank you again.