官术网_书友最值得收藏!

Managing our product data

Currently, we have a form that can be used for two purposes. It can be used to enter a new product as well as to edit existing ones. We are going to reuse this form. Reuse is the fastest path to make things easier. However, we must not think that it is the only way to do things. What we should think is that not reusing something requires a reason for doing it differently.

In order to edit an existing product, we will have to create a page that shows the existing product records. Let us create the page:

<!--- Example: product_list.cfm --->
<!--- Processing --->
<cfscript>
objProduct = createObject("component","product").init(dsn="cfb");
rsProducts = objProduct.getRecordset();
</cfscript>
<!--- Content --->
<h3>Select a product to edit.</h3>
<ul>
<cfoutput query="rsProducts">
<li>
<a href="product_edit.cfm?id=#rsProducts.id#">#rsProducts.name#
</li>
</cfoutput>
</ul>

There is no new code here. This is the browser view that we get when we run this page. Here, we will post our edit page. Before you run the code, take the code from 3_1.cfm that we wrote at the beginning of the chapter and save a copy as product_edit.cfm to make the page work correctly when someone clicks on any of the products:

Now, we will click on a product. Let us manage the Watermelon Plant for now and observe what happens on the next page:

This is our edit page, and we will modify it so that it can get the data when we click through from our list page.

主站蜘蛛池模板: 五大连池市| 六盘水市| 道真| 酒泉市| 静海县| 兴义市| 贺州市| 汉阴县| 正宁县| 雷州市| 和平县| 嘉善县| 宁安市| 富锦市| 岳阳市| 武汉市| 磴口县| 万山特区| 泗洪县| 台北市| 兰考县| 尚志市| 安多县| 齐河县| 历史| 宁国市| 论坛| 长乐市| 崇仁县| 湖南省| 海伦市| 西藏| 高邮市| 砀山县| 柘荣县| 益阳市| 百色市| 景宁| 丹阳市| 深泽县| 凌源市|