11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 19 • TEMPLATING WITH SMARTYwww.it-ebooks.infoKeep in mind that all popular templating solutions follow the same core set of implementationprinciples. Like programming languages, once you’ve learned one, you’ll generally have an easier timebecoming proficient with another. Therefore, even if you’ve decided that Smarty isn’t for you, you’re stillinvited to follow along. The concepts you learn in this chapter will almost certainly apply to any othersimilar solution. Furthermore, the intention isn’t to parrot the contents of Smarty’s extensive manual,but rather to highlight Smarty’s key features, providing you with a jump-start of sorts regarding thesolution, all the while keying in on general templating concepts.At the time of this writing, Smarty 3 was available as a release candidate, meaning it is due tobecome the official release in the very near future. Smarty 3 is a complete rewrite of its predecessor, andit will only work with <strong>PHP</strong> 5 and newer. Because the version 3 release is imminent, I have opted toupdate this chapter to reflect the latest changes and features found in this version. While much of theversion 2 syntax is still supported, many features are considered deprecated; in other words, if you havealready deployed Smarty 2-specific code, you might consider upgrading the syntax to reflect the latestchanges.Installing SmartyInstalling Smarty is a rather simple affair. To start, go to www.smarty.<strong>net</strong> and download the latest stablerelease (because of the timing of the pending 3.0 release, I am using 3.0rc3 to write and test the codefound in this chapter). Then follow these instructions to get started using Smarty:1. Untar and unarchive Smarty to some location outside of your web documentroot. Ideally, this location would be the same place where you’ve placed other<strong>PHP</strong> libraries for subsequent inclusion into a particular application. Forexample, on Linux this location might be the following:2. /usr/local/lib/php/includes/smarty/3. On Windows, this location might be the following:4. C:\php\includes\smarty\5. Because you’ll need to include the Smarty class library into your application,make sure that this location is available to <strong>PHP</strong> via the include_pathconfiguration directive. Namely, this class file is Smarty.class.php, which isfound in the Smarty directory libs/. Assuming the previous locations, on Unixyou should set this directive like so:6. include_path = ".;/usr/local/lib/php/includes/smarty/libs"7. On Windows, it would be set as so:8. include_path = ".;c:\php\includes\smarty\libs"9. You’ll probably want to append this path to the other paths already assigned toinclude_path because you are likely integrating various libraries intoapplications in the same manner. Remember that you need to restart the webserver after making any changes to <strong>PHP</strong>’s configuration file. Also note thatthere are other ways to accomplish the ultimate goal of making sure that yourapplication can reference Smarty’s library. For example, you could provide thecomplete absolute path to the class library. Another solution involves setting apredefined constant named SMARTY_DIR that points to the Smarty class library390

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!