PHP
  Home arrow PHP arrow Page 6 - JV’s Power Tips for PHP (1)
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

JV’s Power Tips for PHP (1)
By: Justin Vincent
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 3
    2003-01-29

    Table of Contents:
  • JV’s Power Tips for PHP (1)
  • Never Breaking Out of PHP
  • Basic Template Theory
  • Refining the Previous
  • Accessing Other Variables from Within this Type of Template
  • Using Objects to Store Multiple Output Values
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    JV’s Power Tips for PHP (1) - Using Objects to Store Multiple Output Values


    (Page 6 of 7 )

    Another reason why this is useful is that it files your output variables into one (or a few) objects. It also means that in our function get_template() we can get rid of this:

    <?php
        // etc.
        
        // Make sure that all global variables are available to this functions..
        foreach ( $GLOBALS as $key => $val )
        {
          global ${$key};  
        }

        // etc.

    ?>


    ...which, in truth, is a little costly and replace it with this:

    <?php
        // etc.
        
        // We only need to make the object $output global to this function..
        global $output;

        // etc.

    ?>


    Going back to our table template. It would look like this:

    <table>
      <tr>
        <td>
          $output->dynamic_text
        </td>
      </tr>
    </table>


    Of course, you don’t have to write your own template system if you don’t want to. I just happen to be a control freak who likes to know the structure of all the code I use. There are plenty of pre-built template systems out there that can save you hours of coding (e.g. Smarty). Even so, the principle is still the same:
    1. Don’t break out of PHP tags.
    2. Abstract HTML content from programming logic.

    More PHP Articles
    More By Justin Vincent


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT