1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP and MySQL Web Development - P117 pdf

5 244 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 66,66 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Extending the Project We have built a fairly simple shopping cart system.There are many additions and enhancements we could make: n In a real online store, you would need to build some k

Trang 1

552 Chapter 25 Building a Shopping Cart

<tr>

<td>Description:</td>

<td><textarea rows="3" cols="50"

name="description">

<?php echo $edit?$book['description']:''; ?>

</textarea></td>

</tr>

<tr>

<td <?php if (!$edit) echo 'colspan="2"'; ?> align="center">

<?php

if ($edit) // we need the old isbn to find book in database // if the isbn is being updated

echo '<input type="hidden" name="oldisbn"

value="'.$book['isbn'].'">';

?>

<input type="submit"

value="<?php echo $edit?'Update':'Add'; ?> Book">

</form></td>

<?php

if ($edit) { echo '<td>';

echo '<form method="post" action="delete_book.php">';

echo '<input type="hidden" name="isbn"

value="'.$book['isbn'].'">';

echo '<input type="submit"

value="Delete book">';

echo '</form></td>';

}

?>

</td>

</tr>

</table>

</form>

<?php

}

If we pass in an array containing the book data, the form will be rendered in edit mode and will fill in the fields with the existing data:

<input type="text" name="price"

value="<?php echo $edit?$book['price']:''; ?>">

We even get a different submit button In fact, for the edit form we get two—one to update the book, and one to delete it.These call the scripts edit_book.phpand delete_book.php, which update the database accordingly

Listing 25.19 Continued

Trang 2

553 Using an Existing System

The category versions of these scripts work in much the same way except for one thing.When an administrator tries to delete a category, it will not be deleted if any books are still in it (This is checked with a database query.) This avoids any problems we might get with deletion anomalies.We discussed these in Chapter 7, “Designing Your Web Database.” In this case, if a category was deleted that still had books in it, these books would become orphans.We wouldn’t know what category they were in, and we would have no way of navigating to them!

That’s the overview of the administration interface For more details, refer to the code—it’s all on the CD-ROM

Extending the Project

We have built a fairly simple shopping cart system.There are many additions and enhancements we could make:

n In a real online store, you would need to build some kind of order tracking and fulfillment system—at the moment, there’s no way to see the orders that have been placed

n Customers want to be able to check the progress of their orders without having to contact you.We feel that it is important that a customer does not have to log in to browse However, providing existing customers a way to authenticate themselves gives them the ability to see past orders, and gives you the ability to tie behaviors together into a profile

n At present, the images for books have to be FTPed to the image directory and given the correct name.You could add file upload to the book insertion page to make this easier

n You could add user login, personalization, and book recommendations; online reviews; affiliate programs; stock level checking; and so on.The possibilities are endless

Using an Existing System

If you want to get a highly featured shopping cart up and running quickly, you might want to try using an existing shopping cart system One well known Open Source cart implemented in PHP is FishCartSQL, available from

http://www.fishcart.org/

This has a lot of advanced features such as customer tracking, timed sales, multiple lan-guages, credit card processing, and support for multiple online shops on one server Of course, when you use an existing system, you always find there are things that it does not have that you want, and vice versa.The advantage of an Open Source product is that you can go in and change the things you don’t like

Trang 3

554 Chapter 25 Building a Shopping Cart

Next

In the next chapter, we’ll look at how to build an online content management system suitable for managing digital assets—this can be useful if you are running a content-based site

Trang 4

26 Building a Content Management

System

IN THIS CHAPTER,WE’LL LOOK AT Acontent management system for storing, indexing, and searching text and multimedia content

Content management systems are extremely useful on Web sites where the site con-tent is maintained by more than one author, where maintenance is performed by non-technical staff, or where the content and graphic design are developed by different peo-ple or departments

We will build an application that helps authorized users to manage an organization’s digital assets

We will cover the following:

n Presenting Web pages using a series of templates

n Building a search engine that indexes documents according to metadata

The Problem

Let’s imagine that the busy Web development team for SuperFastOnlineNews consists of

an excellent graphic designer and some award-winning writers.The site contains regu-larly updated news, sports, and weather pages.The main page shows the latest headline from each of the three category pages

At SuperFastOnlineNews, the designers ensure that the Web site content looks great This is what they do best.Writers, on the other hand, write excellent articles, but can’t draw well or build Web sites

We need to allow everyone to concentrate on what they are best at and bring their output together to provide the super fast news service that the name implies

Trang 5

556 Chapter 26 Building a Content Management System

Solution Requirements

We need to produce a system that

n Increases productivity by having the writers concentrate on writing and the designers on designing

n Allows the editor to review stories and decide which ones should be published

n Presents a consistent look and feel throughout the site using page templates

n Allows writers access only to their designated areas of the site

n Enables the look and feel to be easily changed for a section or throughout the site

n Prevents live content from being changed

Editing Content

First, we need to think about how we will get content into the system, and how we will store and edit that content

Getting Content into the System

We need to decide on a way that stories and design components will be submitted Three possible methods can be used

FTP

The writers and designers could be given FTP access to areas on the Web server, and they could then upload files from their local machine to the server.There would need to

be a rigid naming standard for the uploaded files (to identify which pictures belonged to which stories) or a Web-based system to deal with this separately from the FTP upload Using FTP also creates issues with permissions in this situation Because of the flexi-bility required by this example, we will not be using FTP to allow users to upload files

File Upload Method

As we discussed in Chapter 16, “Interacting with the File System and the Server,” the HTTP protocol provides a method for files to be uploaded via the Web browser PHP is able to deal with this very easily

The file upload method also gives us the opportunity to store text in a database rather than as a file.To do this, we would read in the temporary file and store its contents in the database, rather than copying it to another place in the file system.We will not use file upload for stories in this project

We will discuss the superiority of a database over the file system later

Editing Online

We can let users create and edit documents without using either FTP or file upload Instead you can give the contributors a large text area input box onscreen in which their story content can be edited

Ngày đăng: 07/07/2014, 03:20

TỪ KHÓA LIÊN QUAN