With the actions and views defined, its time for the moment of truth. Try navigating to the following pages and see what happens:
Next, consider experimenting by adding a new action and class and set of corresponding views. Just copy and rename one of the controllers, being sure to follow the same conventions used in the original class. Searching the Web with Zend_Service_Yahoo Table 25-1 presented just some of the dozens of Zend Framework components at your disposal, therefore as you might imagine it's difficult to decide which to demonstrate in this brief chapter. After some consideration it seems ideal to introduce the Zend_Service_Yahoo component, as it shows how the framework can really shine at simplifying otherwise fairly complex operations, in this case Web Services interaction. The Zend_Service_Yahoo component allows you plug into Yahoo!'s search engine, as well as search images, businesses, and news. Therefore, suppose you want to add a page to the chess club Web site that displays the latest chess news. This news page will appear at http://www.example.com/news/, meaning a new controller and view will need to be added. Note In order to follow along with these examples youll need to register for a free Yahoo! application ID. Navigate to http://developer.yahoo.com/ for more information.
Create the Controller The controller, named NewsController.php, should be placed in the application/modules/default/ controllers directory. This controller is responsible for retrieving the news via the Yahoo! component and sending that data to the view. The NewsController.php script is found in Listing 25-7. Listing 25-7. The Chess Club's News Controller (NewsController.php) <?php // Load the Zend_Controller_Action class // Load the Yahoo! Service class class NewsController extends Zend_Controller_Action public function indexAction() // Invoke the Yahoo! service // Execute the search // Send the search results to the view } Of course, in a real-world situation you might use the controller to retrieve some user preferences from a database pertinent to region, allowing for more geographically targeted chess-related news results. Those preferences could then be passed to the view much in the same way the other properties were passed in previous examples. Create the View The view's role is simple: render the search results in an easily readable format. This is done by looping through each result and outputting it to the browser. This file, named index.phtml, should be placed in the directory application/modules/default/views/scripts/news/. Listing 25-8 presents this simple but effective view. Listing 25-8. The Chess Club's News View (index.phtml) <?php <h4>The Latest Chess News</h4> <?php ?> <?php Executing this code will produce news-related output similar to that shown in Figure 25-1.
Summary This chapter provided but a glimpse of what the Zend Framework is capable of; but hopefully it has served its purpose: to get your mind racing about just how productive Web frameworks can make you. In the following chapter, an introduction to Oracle, you'll begin the next learning phase of this book.
blog comments powered by Disqus |
|
|
|
|
|
|
|