2004年的php

php的开发模式基本成型了.以后也不会刻意去学习他的相关技术了,因此在这里我把php的开发的点滴写出来.留个纪念.
第一章  php目录树
        下载自己常用的pear包,把他放在php的安装目录下(d:/php/Pear).pear的目录树可以参考cvs.php.net.最基本的是:/pear.php,/pear,/db.php,/db,/system.php,/config.php,/config,/HTTP/Upload.php等.
       在php根目录下建立include_path的文件夹,我的取名叫lib(d:/php/lib),下载常用的包放在这里.比如Smarty,Adodb等,也可以在这里存放自己常用的类函数,比如我的分页类(class.pager.php).
      文件放好后,编辑php.ini文件,修改include_path参数。把它改为.;d:/php/Pear;d:/php/lib。
      目录树设置完成。
第二章  应用程序目录
     当然,你可以完全参考phpmvc得目录结构,设置WEB-INFO得那种jsp结构的目录。我的目录树如下:
/lib
/lib/classes
/lib/functions
/lib/lang
/inc
/inc/inc.config.php
/inc/config.xml
/images
/uploads
/admin
/admin/FCKeditor_2.0rc1
/admin/images
在目录lib/classes下存放应用程序的class文件,比如class.news.php.
在目录lib/functions下存放频繁调用的代码段,我把它写成function防在这里。
/inc/inc.config.php 用来解析config.xml,并创建数据库连接。
/inc/config.xml 用xml格式列出了应用程序的一些信息,比如数据库用户名和密码等
第三章 代码实例
1,config.xml
<config>
<hostname>http://www.lhb.cn</hostname>
<hosttitle>lhb</hosttitle>
<hostip>127.0.0.1</hostip>
<charset>gb2312</charset>
<database_conn>localhost</database_conn>
<database_user>root</database_user>
<database_pwd></database_pwd>
<database_name>nt</database_name>
<document_root>D:/phpsite/XYCW</document_root>
<host_root>http://localhost/XYCW/</host_root>
<include_path>D:/phpsite/XYCW/lib</include_path>
<adodb_debug>false</adodb_debug>
<smarty_debug>false</smarty_debug>
<mime>
<gif>image/gif</gif>
<jpg>image/jpeg</jpg>
<jpeg>image/pjpeg</jpeg>
<swf>application/x-shockwave-flash</swf>
</mime>
<copyright>
<author>hb_lv@hotmail.com</author>
<qq>57893609</qq>
<time>28/12/2004</time>
<workplace>office</workplace>

</copyright>

</config>
2.inc.config.php
<?php
require('Config.php');
$filesrc="config.xml";
$c=new Config();
$root =& $c->parseConfig($filesrc, 'xml');
$config=$root->getItem('section','config');
$confArr=$config->toArray();
?>
<?
$sys_include_path=ini_get('include_path');
$include_path=$sys_include_path.";".$confArr[config][include_path];
ini_set("include_path",$include_path);
?>
<?
$database_conn=$confArr[config][database_conn];
$database_user=$confArr[config][database_user];
$database_pwd=$confArr[config][database_pwd];
$database_name=$confArr[config][database_name];
//mysqlConn
//$conn = mysql_pconnect($database_conn, $database_user, $database_pwd) or die(mysql_error());
//mysql_select_db($database_name);
//adodbConn
include('adodb423/adodb.inc.php');
$adodbConn = &ADONewConnection('mysql');
$adodbConn->debug = false;
$adodbConn->PConnect($database_conn,$database_user,$database_pwd,$database_name);
?>
3,site.php(修改config.xml)

<?PHP
require('Config.php');
require 'Smarty/Smarty.class.php';
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$smarty->left_delimiter= "<{";
$smarty->right_delimiter="}>";
$operation = (isset($_GET['op']))?$_GET['op']:$_POST['op'];
switch ($operation){
 case "updateSiteInfoAction":
 updateSiteInfo();
 break;
 default:
 getSiteInfo();
 break;
}
#
function getSiteInfo(){
 global $smarty;
 $filesrc="config.xml";
 $c=new Config();
 $root =& $c->parseConfig($filesrc, 'xml');
 $config=$root->getItem('section','config');
 $confArr=$config->toArray();
 $smarty->assign("title",$confArr['config']['hosttitle']);
 $smarty->assign("name",$confArr['config']['hostname']);
 $smarty->assign("toyear",$confArr['config']['toyear']);
 $smarty->assign("alertLenght",$confArr['config']['alertlenght']);
 $smarty->display("site.htm");
}
function updateSiteInfo(){
 global $smarty;
 global $lang;
 $filesrc="config.xml";
 $c=new Config();
 $root =& $c->parseConfig($filesrc, 'xml'); 
 $config=$root->getItem('section','config');
 $confArr=$config->toArray();
 /*get the input data */
 $name=$_POST['name'];
 $title=$_POST['title'];
 $toyear=$_POST['toyear'];
 $alertlenght=$_POST['alertLenght'];
 /*update data */
 $confArr['config']['hostname']=$name;
 $confArr['config']['hosttitle']=$title;
 $confArr['config']['toyear']=$toyear;
 $confArr['config']['alertlenght']=$alertlenght;
 
 $c2=new Config();
 $conf=$confArr['config'];
 $root=&$c2->parseConfig($conf, 'phparray');
 $c2->writeConfig('config.xml', 'xml', array('name' => 'config'));
 
 /* output*/
 $smarty->assign("message",$lang['updateOK']);
 $smarty->display("post.htm");
}
?>
   
当然,如果上传到服务器,可以把lib下的所有东西拷贝到应用程序的目录下面。然后把修改inc.config.php中的变量include_path=d:/...../lib;d:/...../lib/Pear

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值