程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 用PHP5進行三層開發

用PHP5進行三層開發

編輯:關於PHP編程

原文:http://www.onlamp.com/pub/a/php(做為現在的主流開發語言)/2004/12/09/three_tier.html
Three-Tier Development with php(做為現在的主流開發語言) 5
by Luis Yordano Cruz
12/09/2004

此文演示了php(做為現在的主流開發語言)三層開發的強大功能,PEAR::DB_DataObject用於業務邏輯,Smarty用於顯示邏輯,這裡假設你熟

悉了HTML,Smarty,PEAR::DB_DataObject,MySQL(和PHP搭配之最佳組合)和php(做為現在的主流開發語言)5.如果你需要補充知識,下面的文章解釋了一些原理:

用php(做為現在的主流開發語言) DataObject簡化業務邏輯
Smarty簡介:一個php(做為現在的主流開發語言)模板引擎
php(做為現在的主流開發語言)可伸縮性:Myth

你應該已安裝和配置好了apache(Unix平台最流行的WEB服務器平台),MySQL(和PHP搭配之最佳組合),和php(做為現在的主流開發語言)5(或者iis(微軟的WEB服務器平台),MySQL(和PHP搭配之最佳組合)5和php(做為現在的主流開發語言))

PEAR::DB_DataObject
PEAR::DB_DataObject 是一個用戶數據庫訪問的抽象API.它是一個基於PEAR::DB的SQL構建器和數據建模層.它

把數據庫表映射到php(做為現在的主流開發語言)類並且提供像SELECT,INSERT,UPDATE,和DELETE這樣的公共SQL函數.這使即使不了

解SQL的開發者也可以寫出好的數據庫訪問代碼,並且鼓勵演示邏輯和業務邏輯有一個清晰的分離.

(DB_OO已經移動到的PEAR,現在是DB_DataObject,如果你有老的代碼要更新,查看關於從老的db_oo代碼更新到

DB_DataObjects的注釋).

相關閱讀
 
Upgrading to php(做為現在的主流開發語言) 5
By Adam Trachtenberg

Table of Contents
Index
Sample Chapter

Read Online--Safari Search this book on Safari:
    
 Only This Book All of Safari
Code Fragments only 
DataObject performs two tasks. First, it builds SQL statements based on the objects variables and the builder

methods. Second, it acts as a datastore for a table row. Theres a core class, which you extend for each of

your tables so that you put the data logic inside the data classes. Theres also an included Generator to make

your configuration files and your base classes.

DataObject 執行兩個任務.第一,它構建基於對象變量的SQL語句和構建器方法.第二,它作為數據庫表的數據存

儲.這裡有個核心類,對於每個表繼承它,以使你把數據邏輯放入數據類中.這裡還包括一個生成器,


DataObject 極大的簡化了數據庫訪問代碼,它使開發大型的,數據驅動的站點更加容易.

At present, Alan Knowles, the lead developer of PEAR::DB_DataObject, is working on a new project called DBDO,

a C implementation of the PEAR package DB_DataObjects, based on libgda. His goal is to create the next

generation of PEAR::DB_DataObjects.

SMARTY

Smarty是一個從web頁演示中分離內容的php(做為現在的主流開發語言)模板引擎.它使用GPL許可.

Large projects commonly separate the role of the graphic designer from that of the programmer. However,

programming in php(做為現在的主流開發語言) has the tendency to combine those two roles in a person and inside the code. This can bring

difficulties when it comes time to change some part of the pages design. If the page mixes content and

presentation, the developer has to crawl through the program to find the presentation. Smarty helps to solve

this problem.

Combining the Two
The first thing to do when starting this project is to create a workspace in which to store the projects code.

Then its time to configure PEAR::DB_DataObject to connect to the MySQL(和PHP搭配之最佳組合) database MySQL(和PHP搭配之最佳組合) (name: example),

map the database tables to php(做為現在的主流開發語言) classes, and then configure Smarty for the presentation tier for the user. Here

are those steps in more detail:


創建工作環境

創建一個叫做dataobjects的目錄.

 

從命令行安裝PEAR::DB_DataObject,鍵入:
>pear install Date

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved