Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
One of the most useful new features in Dreamweaver CS5 for PHP developers is code hinting. For this demonstration, I'll use a set of files in the folder 03_managingcode > 01_codehinting. There's just one file in this folder, phpinfo.php. It has the PHP info command. I'll run this file on the server by clicking Live View and copying the file over to the resting server, and show you that the PHP info command outputs information on the PHP server, such as the build date of the server, the operating system, the location of the PHP INI file, and so on.
I'll exit Live View. The code hinting feature gives you a list of all of the commands in the PHP language, variables and functions that you have defined in your own file, and also a lot more information. I'm going to start in this exercise by showing you how to use code hinting on commands that are a part of PHP. I'll place the cursor before the PHP info command, and then I'm going to use a feature called the date function.
The date function returns the current date and time on the server. I'll type in an echo command and then type in the word "date." To get to code hinting, press Ctrl+Space. It's the same keyboard shortcut, regardless of whether you're working on Windows or Mac. The date function takes one required argument and one optional argument. The required argument is a format string that designates how the date should be formatted. When you press Ctrl+Space, you not only a list of all of the function and variable names that have the word "date" in it, but when the item you want is selected, you'll also get documentation.
I'm going to scroll down in the documentation and show you that it provides a list of all of the characters that you can use in your format string. So, for example, a lower d means the current day as a numeric value with leading zeroes. The uppercase D means a text representation of the day in three characters, such as Mon for Monday. And the lower case day is the day of the month without leading zeroes, again numerically. I'm going to output the current time, so I'll scroll down in the listing till I get to the Time section, and I'll show you that the letter g, in lower case means the 12-hour format of an hour without leading zeroes, and the letter I means the number of minutes with leading zeroes.
You can use whatever non-alphabetical characters you want to format these values. So I'm going to place my cursor back into the code, and put in an opening paren and then a quote, then g for the hour, a colon and a lower case I for the minutes. I'll close that string with a quote, and then I'll close the whole thing with a parenthesis. I'll save my changes and then click on Live View. I'll update the copy on the testing server and show you the current time, which comes back as 7:06.
You won't see your actual time unless you just happen to be in the right time zone. It's up to you to control the current time zone, and once again, PHP provides a function for this. I'll place the cursor before the echo command and make a new line. I'll once again type in the word "date," and press Ctrl+Space, and then I'll scroll down to the function, date_default_timezone_set. You pass a string into this function. To find out what the available strings are for this function, scroll down a little ways into the documentation, and you'll see a link for the list of supported time zones.
I'll click there, and that opens a browser to the PHP documentation on the web. You do need an Internet connection at this point to see this information. Then from there, I'll click into America, and from there, I'll locate my particular time zone, which I'm going to set as America/Los_Angeles. I'll locate that string and copy it to the clipboard from the browser. Then I'll return back to Dreamweaver. I'll press Ctrl+Space, and I'll once again go down to date_default_timezone_set, and this time I'll press Enter. Then I'll type in a quote and paste in my time zone identifier, then a closing quote, a closing parenthesis, and a semicolon.
Then after I've set the time zone but before I output the date, I'll put in another new line of code and echo, and then I'll output a literal string of The current time is:. I'll save my changes. Then I'll click over on the design area, and that causes Dreamweaver to prompt me to update the copy of my file on the testing server. I'll click Yes, and Yes, and there is the result. Now I'm seeing the current time in my time zone, or whichever time zone I've set in the date_default_timezone_set function.
The goal of this exercise is to show you how to use the code hinting to help you find and insert long function names very easily, and also how to use the code hinting feature to get to the PHP documentation for the particular function you're interested in. The goal of this feature of Dreamweaver is to make it easier for those who like to do a little bit of hand-coding in PHP, to get to the features of the language that they need and insert the code correctly.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97336 Viewers
61 Video lessons · 84586 Viewers
71 Video lessons · 68788 Viewers
56 Video lessons · 101265 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.
Your file was successfully uploaded.