[ Pobierz całość w formacie PDF ]
.This processcontinues until Zope finds the object or gets to the root folder.If Zope can't find the object in the root it givesup and raises an exception.You'll see this kind of dynamic behavior in many different places in Zope.This technique is calledacquisition.A folder is said to acquire a object by searching for the object in its containers.Chapter 5: Creating Basic Zope Applications 65IntroductionThe Special Folder Object index_htmlAs you've seen, folders can acquire all kinds of objects.There is one special object that Zope uses to display afolder.This object is named index_html.The index_html object provides a default view of the folder.This is analogous to how an index.html fileprovides a default view for a directory in Apache and other web servers.For example, if you create an index_html object in your Invoices folder and view the folder by clicking theView tab or by visiting the URL http://localhost:8080/Invoices/, Zope will call the index_html object on theInvoices folder.A folder can also acquire an index_html object from its parent folders just as it can acquire any object.Youcan use this behavior to create a default view for a bunch of folders all in one place.If you want a differentdefault view of a given folder, just create a custom index_html object in that folder.This way you canoverride the index_html object defined higher up.Building the Zope Zoo WebsiteIn this section, you'll create a simple web site for the Zope Zoo.As the Zoo webmaster, it is your job to makethe web site easy to use and manage.Here are some things you'll need:" Zoo users must easily move around the site, just as if they were walking through a real Zoo." All of your shared web layout tools, like a Cascading Style Sheet (CSS), must be in one easy tomanage location." You must provide a simple file library of various documents that describe the animals." You need a site map so that users can quickly get an idea of the layout of the entire Zoo." A Guest book must be created so that Zoo visitors can give you feedback and comments about yoursite." A what's new section must be added to the guest book so that you can see any recent comments thathave been added.Navigating the ZooIn order for your navigation system to work, your site will need some basic structure through which tonavigate.Create some folders in your Zope system that represent the structure of your site.Let's use a zoostructure with the following layout, as shown in Figure 5-1.The Special Folder Object index_html 66IntroductionFigure 5-1 Zoo folder structure.The main structure of the Zope Zoo contains three top level folders, Reptiles, Mammals and Fish.To navigateyour site, users should first go to your home page and click on one of the top level folders to enter thatparticular part of the Zoo.They should also be able to use a very similar interface to keep going deeper intothe site; i.e.the snakes section.Also, the user should be able to back out of a section and go up to the parentsection.You can accomplish this easily with Zope.In your ZopeZoo folder, create a DTML Method called navigation:The method you just created shows a list of links to the various sub-sections of the zoo.It's important tonotice that this method can work on any zoo folder since it makes no assumptions about the folder.Also sincewe placed this method in the ZopeZoo folder, all the zoo folders can acquire it.Now, you need to incorporate this method into the site.Let's put a reference to it in thestandard_html_header object so that the navigation system is available on every page of the site.Yourstandard_html_header could look like this:Next we need to add a front page to the Zoo site and then we can view the site and verify that the navigationworks correctly.The Special Folder Object index_html 67IntroductionAdding a Front Page to the ZooNow, you need a front page that serves as the welcome screen for Zoo visitors.Let's create a DTML Methodin the ZopeZoo folder called index_html with the following content:Welcome to the Zope ZooHere you will find all kinds of cool animals.You are inthe section.Take a look at how your site appears by clicking on the View tab in the root folder, as shown in Figure 5-2.Figure 5-2 Zope Zoo front page.Here you start to see how things come together.At the top of your main page you see a list of links to thevarious subsections.These links are created by the navigation method that is called by thestandard_html_header method.You can use the navigation links to travel through the various sections of the Zoo.Use this navigationinterface to find the reptiles section.Zope builds this page to display a folder by looking for the default folder view method ,index_html.It walksup the zoo site folder by folder until it finds the index_html method in the ZopeZoo folder.It then calls thismethod on the Reptiles folder.The index_html method calls the standard_html_header method which in turncalls the navigation method.Finally, the index_html method displays a welcome message and calls thestandard_html_footer.Adding a Front Page to the Zoo 68IntroductionWhat if you want the reptile page to display something besides the welcome message? You can replace theindex_html method in the reptile section with a more appropriate display method and still take advantage ofthe zoo header and footer including navigation
[ Pobierz całość w formacie PDF ]