Now that there's a URL helper class available for testing purposes, it'd be useful to see how it can be put into action, right? With that idea in mind, below I coded a group of examples that show precisely how to use the helper for retrieving URL-related information about a PHP script running on a Windows web server. Here are the corresponding code samples: $urlhelper = new URLHelper(); echo $urlhelper->get_document_root(); /* // displays the following C:/Program Files/Apache Group/Apache2/htdocs */
echo $urlhelper->get_request_method(); /* displays the following get */
echo $urlhelper->get_query_string(); /* displays the following fname=Alejandro&lname=Gervasio */
echo $urlhelper->get_request_uri(); /* displays the following /helpers/helper_example.php */
echo $urlhelper->get_script_filename(); /* displays the following C:/Program Files/Apache Group/Apache2/htdocs/helpers/helper_example.php */
echo $urlhelper->get_script_url(); /* displays the following /helpers/helper_example.php */ As you can see above, the methods of the URL helper class have been utilized for retrieving some typical values about the script being executed, such as the request URI and the script's URL, the root of the web server and the eventual query string, and so forth, assuming that these parameters are available to be fetched from the web host. Again, it's feasible to add more methods to the helper that perform more complicated tasks, but I guess the class in its current version should be enough to demonstrate how to create a URL helper in PHP 5. Finally, feel free to edit all of the examples shown in this tutorial, particularly if you're planning to include different kinds of helper classes in your own framework. Final thoughts That's about it. In this third installment of the series, I provided you with the basic pointers for building a URL-handling helper class. Of course, the methods of this sample class should be improved to fit the requirements of production environments, but they should serve to demonstrate how to create a helper that generates dynamic URLs. In the next article, I'm going to enhance the signature of this class by declaring its methods static, which is pretty similar to the process covered in the preceding tutorial. Don't miss the upcoming tutorial!
blog comments powered by Disqus |
|
|
|
|
|
|
|