Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
After configuring your third-party library, you can then use the code hints that are implemented with Dreamweaver to more easily and accurately do your PHP hand coding. For this demonstration, I'll use a version of my site in the folder 03_managingcode/05_sitecodehints, and I'll point my site to that folder. When you configure site code hinting, a file is added to your site, named dw_php_codehinting.config.
You can open this file in Dreamweaver, and you'll see that it's a simple text file that includes listings pointing to the absolute folder locations that contain your third-party files. If you're working on Mac OS X with MAMP and you placed the Zend Framework in the location I recommended, under the MAMP installation folder, in this file, you can change every instance of c:/phpincludes to /applications/MAMP. There is more information stored in the background; this file wasn't the whole story. But this is how you can tell that your particular code hinting setup has been added to the site.
I'll demonstrate using code hinting by using your class named Zend_Date. The Zend_Date class is a PHP class that does a lot more than the standard PHP date class. I'll be adding the code in a file called DateUtility.php. This file is being included and used in a file called footer.php already. In the current version of the file, I'm setting the time zone and using the PHP date function to output the time in the current format.
I'm going to add the use of the Zend_Date class here. The first step, before you can use any of the features of any PHP class, is to include the file that defines the class. You typically do this with a PHP command called include_once. I'll place the cursor at the line that has the class declaration and then create an empty line above it. Then I'll type in include_once, and then after an opening parenthesis, I'll add the relative location of the date class I'm interested in.
I've already configured my PHP installation to automatically include anything in the Zend framework library. So all I need to de here is start off with the Zend folder, and then after a forward slash, name the class that I want to include, Date.php. If you're not sure of the names of the PHP files, take a look at the phpincludes folder, at the ZendFramework library folder, and then go to Zend. Down at the bottom, you'll see a whole listing of all the files that should be included.
I'm including this one, Date.php. This file in turn includes all of the classes that are required: the DateObject, Locale, Format, and Math. It's up to the Zend framework to go and get all the resources it needs for all of the complex features that are implemented. I'll close these windows and return to Dreamweaver. So I've included the definition of the date class. Now, I can use it in my PHP code. I'll place the cursor inside the getCurrentTime function and press Enter to create a new line, and next, I'll create an instance of the Zend_Date class.
I'll create a variable named zendDate - you can name this variable anything you want - and then I'll use the new keyword and then type the beginning of the class name. All classes in the ZendFramework library start off with the word "Zend." So I'll type in "Zend" and an underscore, and then I can scroll down and select the class that I want. I'm going to use Zend_Date. I'll type in an opening parenthesis, and I'm showing that there are three possible arguments, or values I can pass in: date, part, and locale.
I'm going to ignore those properties for the purpose of this exercise, and
not pass in any values.
When you create a new instance of the Zend_Date class without passing in any
properties, it represents the current date and time on the server.
So, now I have a copy of the class, and I can call its functions.
I'll place the cursor down toward the bottom of the function, after the last
echo command, and I'm going to add a couple of echo commands that output some literal text.
The first one will add a
Make sure that you include semicolons at the end of every line. The next echo command will output some literal text: The current date is, and then I'm ready to use a feature of the Zend_Date class. Once again, I'll use the echo command, and then I'll use zendDate - that's the name of my variable - and then put in the dash greater than, and I'll see a whole listing of all the features of the Zend_Date class. You'll see that there is an enormous set of methods that you can use to manipulate and inspect various date values.
First, I'm going to use the get method. The get method allows you to output the raw value of the zendDate object. I'll save the change, and then I'll open the file that's using my date utility class, footer.php. I'll look at this file in Live View, making sure that I update the server, and then I'll scroll down in the Live View and show that the current date is being output as a raw numeric value. This is the number of milliseconds from what's called the epoch date of the date object.
Well, that's not exactly what I want to show the user. Instead I'd like to show them a friendly date output. So I'll exit Live View and go back to my code, and I'll go back to DateUtility.php. Instead of using the get method, I'm going to use another method called toString. The toString method, once again, can take a few different arguments: a format, a type, and a locale. I'm going to use a format this time of MMMM and a space, then a lowercase d, a comma and a space, and four Ys.
These are masking values that mean the full name of the month, the date as a numeric value without padding, and a four-digit year. I'll save those changes and then go back to footer.php and look at the files in Live View, copying them to the server, and here is the result of using the Zend_Date class; I'm now getting a nicely formatted date. You'll find that the utility classes in the Zend framework are much more powerful than their raw equivalents in the PHP core libraries.
Many developers like using the Zend framework only for these utility classes, while other developers like to use the entire capability of the Zend framework, which allows you to build complex, well-architected applications, using an application architecture known as Model-View-Controller, or MVC. However you use the Zend framework, Dreamweaver CS5, through its site-specific code hinting, will help you get your code right the first time, both for the Zend framework and for any other third- party PHP libraries you decide to use.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 87333 Viewers
80 Video lessons · 136361 Viewers
59 Video lessons · 55017 Viewers
52 Video lessons · 68876 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.