📄 ch13.htm
字号:
<LI>The directory of your server's protected CGI executables. "Protected"
in this case means that it requires a user to log in for access. Refer to Chapter
3 for more information.
<P>
<LI>The directory of your MiniVend installation. Normally, this directory is the
one in which you untar the file.
<P>
<LI>The user ID number under which your Web server is run. It defaults to the user
ID number for nobody.
</UL>
<P>The easiest way to configure MiniVend straight out of the tar file is to run the
<TT>configure</TT> script, which is located in the MiniVend directory. It asks you
several questions about your system, and it also figures out some information on
its own such as where Perl is installed and whether or not you have installed all
the necessary modules. The configure script is quite user-friendly and will prompt
you for all the information it needs to know. In addition to setting up your configuration
files, it also builds three executables: <TT>svend</TT>, <TT>vlink</TT>, and <TT>mat</TT>.
Finally, it puts all the necessary items in the proper place, optionally installs
the demo system, and starts the minivend.pl server.
<H3 ALIGN="CENTER"><A NAME="Heading9"></A><FONT COLOR="#000077">Overview of Features</FONT></H3>
<P>MiniVend can run in two different modes. In static mode, each CGI catalog request
loads the database to generate the catalog page. In server mode, you start up a MiniVend
server process that loads the product database once and serves the remaining CGI
requests with the product information. As you can well imagine, server mode is much
faster and is recommended. When you run in server mode, and your server goes down
for some reason, one nice feature causes an automatic e-mail notification when someone
attempts to access your catalog but cannot do so because the server is down.</P>
<P>Almost all your catalog pages are stored in a directory outside your usual Web
server document root. The only pages that need to be visible to your Web server are
the base HTML files. All other pages contain MiniVend tags and are stored in the
directory specified by the <TT>PageDir</TT> directive in the minivend.cfg configuration
file.</P>
<P>A remote administration tool that runs as a CGI script is put into a protected
CGI executable directory. It enables you to administer your MiniVend site from any
platform using your favorite browser. I describe this tool, called <TT>mat</TT>,
in more detail later in the chapter.
<H3 ALIGN="CENTER"><A NAME="Heading10"></A><FONT COLOR="#000077">Use and Customization</FONT></H3>
<P>The best way to start using MiniVend is to look at the demo files and tailor them
to your own needs. You need to complete the following steps to get your site up and
running:
<OL>
<LI>Design and create your base HTML document(s) and images.
<P>
<LI>Set up your product catalog.
<P>
<LI>Set up your minivend.cfg file.
<P>
<LI>Set up your catalog search pages.
<P>
<LI>Set up your search result pages.
<P>
<LI>Set up your order page.
<P>
<LI>Set up other miscellaneous pages.
</OL>
<P>The demo sample catalog contains examples of all these items; using it is also
a great way to get started. All accesses into your catalog besides your base HTML
files are through the <TT>vlink</TT> CGI executable. This program looks for the MiniVend
tags within your catalog pages and substitutes items for sale according to your product
database and MiniVend configuration file.</P>
<P>Your base HTML document and images can be designed without any knowledge of the
MiniVend package. This will simply be your virtual storefront window, and it will
be the attraction that brings the user into your store. The links on this page will
be to your MiniVend catalog and search pages described a bit later. Before I get
into those pages, however, you should understand more about how the product catalogs
are designed.
<H4 ALIGN="CENTER"><A NAME="Heading11"></A><FONT COLOR="#000077">Setting Up Your
Product Catalog</FONT></H4>
<P>First, you need to set up your product catalog. The product catalog is contained
in a database file called products.asc, which is an ASCII text file in which each
row is a product item whose fields are delimited using <TT>TAB</TT>, <TT>PIPE</TT>,
or <TT>CSV</TT>. The field names are contained on the first line of the file. These
names must consist entirely of the characters hyphen, underscore, the digits 0 through
9 and the letters A through Z in upper- or lowercase form; they are case sensitive,
and they must match the field names of the <TT>[in_field]</TT> tags in your catalog
HTML files.</P>
<P>The default <TT>TAB</TT> delimiter says to separate each field using a hard tab
character <TT>^I</TT>. For example,</P>
<PRE><FONT COLOR="#0066FF">code description price image
HA_001 Stereo 150.95 stereo.jpg
HV_001 Television 500.95 tv.jpg
</FONT></PRE>
<P>The <TT>PIPE</TT> delimiter separates each field using the pipe character <TT>|</TT>.
For example,</P>
<PRE><FONT COLOR="#0066FF">code|description|price|image
HA_001|Stereo|150.95|stereo.jpg
HV_001|Television|500.95|tv.jpg
</FONT></PRE>
<P>And the <TT>CSV</TT> delimiter specifies fields enclosed in quotation marks and
separated by commas. For example,</P>
<PRE><FONT COLOR="#0066FF">"code","description","price","image"
"HA_001","Stereo","150.95","stereo.jpg"
"HV_001","Television","500.95","tv.jpg"
</FONT></PRE>
<P>You must set the delimiter directive appropriately for the delimiter format you
choose. A set of fields such as <TT>code</TT>, <TT>description</TT>, and <TT>price</TT>
is required. You may define as many additional fields as you need; however, the product
code must be the first field in the line. You can extract customized field values
using the <TT>[data]</TT> tag in your catalog pages.
<H4 ALIGN="CENTER"><A NAME="Heading12"></A><FONT COLOR="#000077">Setting Up Your
minivend.cfg File</FONT></H4>
<P>You also need to set up your minivend.cfg configuration file. Some of this file
is set up for you when you run <TT>configure</TT>; however, you may want to tailor
some variables manually.</P>
<P>The important two variables in this file are <TT>VendURL</TT> and <TT>SecureURL</TT>.
They specify the CGI program used for all links within the catalog. The only difference
between these two variables normally is that VendURL uses the HTTP protocol where
SecureURL uses the HTTPS protocol. Both variables need to specify the URL at which
MiniVend can find the <TT>vlink</TT> executable, which is normally your cgi-bin directory.
This value is set for you during configuration.</P>
<P>Another important set of variables is <TT>PageDir</TT>, <TT>ProductDir</TT>, and
<TT>DataDir</TT>. These variables specify where to find HTML files, product database
files, and other database files. You normally want to separate at least your HTML
pages from your database files. You can separate your product database files from
your extra database files, although doing so is unnecessary. The directories specified
for these variables are relative to the MiniVend installation directory unless they
begin with the / character.</P>
<P>The last variable is the <TT>Database</TT> variable. You can have as many instances
of this variable as you like. The format for the value of this variable is</P>
<PRE><FONT COLOR="#0066FF">database_name database_file delimiter_type
</FONT></PRE>
<P>database_name is a name you choose for the database that is specified when you
use the <TT>[data]</TT> tag in your HTML files. database_file is an ASCII database
file, as described in the preceding section, which resides in the <TT>DataDir</TT>
directory. delimiter_type was also explained in the preceding section; the values
are as follow:
<UL>
<LI>Type 1: Defaults to the same as the products database file.
<P>
<LI>Type 2: Each field contained on its own line, where blank lines delimit records.
<P>
<LI>Type 3: Each field separated by \n%%\n combination and records separated by \n%%%\n
combination.
<P>
<LI>Type 4: CSV
<P>
<LI>Type 5: PIPE
<P>
<LI>Type 6: TAB
</UL>
<P>The minivend.cfg file also contains many other variables. I suggest you look over
the MiniVend documentation for a more detailed and up-to-date reference. You can
configure the values in these files by using the <TT>mat</TT> administrative CGI
tool, which I describe later in this chapter.
<H4 ALIGN="CENTER"><A NAME="Heading13"></A><FONT COLOR="#000077">Setting Up Your
Catalog Pages</FONT></H4>
<P>Catalog pages are simply HTML files with some additional markup. The additional
markup consists of MiniVend tags that are enclosed in square brackets <TT>[]</TT>
rather than HTML's angle brackets <TT><></TT>. The page flow under normal circumstances
consists of catalog.html to order.html to confirmation.html. The catalog page can
be as simple or as complex as you like. I suggest that you start out simple and then
add features as you become more familiar with the capabilities. The catalog page
for the example in this chapter will remain simple. Here, you provide a search page
and a browse-by-category page. The HTML with additional MiniVend markup is shown
in Listing 13.1, and the resulting page is shown in Figure 13.1.
<H3 ALIGN="CENTER"><A NAME="Heading14"></A><FONT COLOR="#000077">Listing 13.1. The
main catalog page.</FONT></H3>
<PRE><FONT COLOR="#0066FF"><HTML><HEAD>
<TITLE>The Web Shopping Network Home Page</TITLE>
</HEAD>
<BODY>
<H1>Welcome to the Web Shopping Network</H1>
<P>
Our store carries the latest products in home electronics. Please feel
free to [page browse] browse [/page] through our collection or
[page descsrch] search [/page] for a particular item.
<P>
As you see an item you would like to purchase, simply add
it to your virtual shopping cart and continue through our catalog.
When you're ready to place your order you can go to our
[page order] order [/page] form to submit the order.
<P>
</BODY></HTML>
</FONT></PRE>
<P>You're going to use the <TT>[page]</TT> tag quite a bit. This tag is similar to
the <TT><A HREF=> HTML</TT> tag. You use it to navigate within your MiniVend
site. <BR>
<BR>
<A HREF="14wpp01.jpg" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/14wpp01.jpg"><TT><B>Figure 13.1.</B></TT></A> The main catalog
page as it will appear in your browser.
<H4 ALIGN="CENTER"><A NAME="Heading15"></A><FONT COLOR="#000077">Setting Up Your
Search Pages</FONT></H4>
<P>Take a closer look now at the <TT>browse</TT> and <TT>descsrch</TT> pages. They
are a bit more interesting because they interact with your product database. These
pages actually contain HTML forms, as shown in Listing 13.2, so they have some additional
MiniVend tags to accommodate these forms.
<H3 ALIGN="CENTER"><A NAME="Heading16"></A><FONT COLOR="#000077">Listing 13.2. The
search page.</FONT></H3>
<PRE><FONT COLOR="#0066FF"><HTML><HEAD>
<TITLE>Search the Web Shopping Network</TITLE>
</HEAD>
<BODY>
<H1>
Search our Product Catalog
</H1>
<P>
<FORM ACTION="[process-search]" METHOD=POST>
<STRONG>Product Keywords</STRONG><BR>
<INPUT TYPE=text NAME="mv_searchspec" SIZE=20>
<BR>
<TABLE>
<TR><TD>
<INPUT TYPE="submit" NAME="mv_todo" VALUE="Search">
<INPUT TYPE="hidden" NAME="mv_doit" VALUE="search">
<INPUT TYPE="hidden" NAME="mv_search_page" VALUE="results">
<P>[finish-order]<BR>
<TD>
Matches per page:
<SELECT NAME="mv_matchlimit">
<OPTION>1
<OPTION>5
<OPTION>10
<OPTION SELECTED>25
<OPTION>50
</SELECT><BR>
<INPUT TYPE="radio" NAME="mv_orsearch" VALUE="no" CHECKED>Match all<BR>
<INPUT TYPE="radio" NAME="mv_orsearch" VALUE="yes">Match any<BR>
<INPUT TYPE="checkbox" NAME="mv_case" VALUE="yes">Case sensitive<BR>
</TABLE>
</FORM>
</BODY></HTML>
</FONT></PRE>
<P>This page contains some interesting MiniVend tags that you should be aware of.
The first you come across is <TT>[process-search]</TT>, which defines the post action
for the form. It tells MiniVend to perform a database search using the criteria entered
by the user. The rest of the MiniVend tags support the search program with the appropriate
criteria. <TT>mv_searchspec</TT> specifies the text for which to search. <TT>mv_matchlimit</TT>
specifies the maximum number of matches to allow being returned. <TT>mv_orsearch</TT>
enables the user to specify searches that match all words entered or one or more
of the words entered. <TT>mv_case</TT> enables the user to specify case-sensitive
searches. In addition to these tags are several other field types that support searching,
as you can see in the resulting form shown in Figure 13.2. For more information on
these field types, refer to the MiniVend documentation, which is included with the
MiniVend package. <TT><BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -