本文主要点:
1.命名规则
类
? 使用大写字母作为词的分隔,其他的字母均使用小写
? 名字的首字母使用大写
? 不要使用下划线('_')
例如
class NameOneTwo
class Name
类->方法
? 采用与类命名一致的规则
例如
class NameOneTwo
{
function DoIt() {};
function HandleError() {};
}
类->属性
? 属**命名应该以字符‘m’为前缀。
? 前缀‘m’后采用于类命名一致的规则。
? ‘m’总是在名字的开头起修饰作用
例如
class NameOneTwo
{
function VarAbc() {};
function ErrorNumber() {};
var $mVarAbc;
var $mErrorNumber;
var $mrName;
}
类->方法(参数)
? 第一个字符使用小写字母。
? 在首字符后的所有字都按照类命名规则首字符大写。
例如
class NameOneTwo
{
function StartYourEngines(
&$rSomeEngine,
&$rAnotherEngine);
}
普通变量命名
? 所有字母都使用小写
? 使用'_'作为每个词的分界。
例如
function HandleError($errorNumber)
{
$error = OsErr($errorNumber);
$time_of_error = OsErr->GetTimeOfError();
$error_processor = OsErr->GetErrorProcessor();
}
普通函数命名
? 函数名字采用C GNU的惯例,所有的字母使用小写字母,使用'_'分割单词。
理由
? 这样可以更易于区分相关联的类名。
例如
function some_bloody_function()
{
}
全局变量
? 全局变量应该带前缀‘g’。
理由
? 知道一个变量的作用域是非常重要的。
例如
global $gLog;
global &$grLog;
定义命名 / 全局常量
? 全局常量用'_'分隔每个单词。
理由
这是命名全局常量的传统。你要注意不要与其它的定义相冲突。
例如
define("A_GLOBAL_CONSTANT", "Hello world!");
静态变量
? 静态变量应该带前缀‘s’。
理由
? 知道一个变量的作用域是非常重要的。
例如
function test()
{
static $msStatus = 0;
}
引用变量和函数返回引用
? 引用必须带‘r’前缀
理由
? 使得类型不同的变量容易辨认
? 它可以确定哪个方法返回可更改对象,哪个方法返回不可更改对象。
例如
class Test
{
var mrStatus;
function DoSomething(&$rStatus) {};
function &rStatus() {};
}
2.书写注释
类的注释
/**
* @ Purpose:
* 访问数据库的类,以ODBC作为通用访问接口
* @Package Name: Database
* @Author: Forrest Gump gump@crtvu.edu.cn
* @Modifications:
* No20020523-100:
* odbc_fetch_into()参数位置第二和第三个位置调换
* John Johnson John@crtvu.edu.cn
* @See: (参照)
*/
class Database
{
……
}
方法注释
/**
* @Purpose:
* 执行一次查询
* @Method Name: Query()
* @Parameter: string $queryStr SQL查询字符串
* @Return: mixed 查询返回值(结果集对象)
*/
function($queryStr){……}
属**或变量注释
/**
* @Purpose:
* 数据库连接用户名
* @Attribute/Variable Name: mDbUserName
* @Type: string
*/
var mDbUserName
if (0)来注释外部代码块
有时需要注释大段的测试代码,最简单的方法就是使用if (0)块:
function example()
{
great looking code
if (0) {
lots of code
}
more code
}
3.书写规则
见全文
4.帮助与共享
见全文
5.其他
见全文
全文地址
http://www.phpchina.cn/jiaocheng/html/supter/2006/0531/110.html
1.命名规则
类
? 使用大写字母作为词的分隔,其他的字母均使用小写
? 名字的首字母使用大写
? 不要使用下划线('_')
例如
class NameOneTwo
class Name
类->方法
? 采用与类命名一致的规则
例如
class NameOneTwo
{
function DoIt() {};
function HandleError() {};
}
类->属性
? 属**命名应该以字符‘m’为前缀。
? 前缀‘m’后采用于类命名一致的规则。
? ‘m’总是在名字的开头起修饰作用
例如
class NameOneTwo
{
function VarAbc() {};
function ErrorNumber() {};
var $mVarAbc;
var $mErrorNumber;
var $mrName;
}
类->方法(参数)
? 第一个字符使用小写字母。
? 在首字符后的所有字都按照类命名规则首字符大写。
例如
class NameOneTwo
{
function StartYourEngines(
&$rSomeEngine,
&$rAnotherEngine);
}
普通变量命名
? 所有字母都使用小写
? 使用'_'作为每个词的分界。
例如
function HandleError($errorNumber)
{
$error = OsErr($errorNumber);
$time_of_error = OsErr->GetTimeOfError();
$error_processor = OsErr->GetErrorProcessor();
}
普通函数命名
? 函数名字采用C GNU的惯例,所有的字母使用小写字母,使用'_'分割单词。
理由
? 这样可以更易于区分相关联的类名。
例如
function some_bloody_function()
{
}
全局变量
? 全局变量应该带前缀‘g’。
理由
? 知道一个变量的作用域是非常重要的。
例如
global $gLog;
global &$grLog;
定义命名 / 全局常量
? 全局常量用'_'分隔每个单词。
理由
这是命名全局常量的传统。你要注意不要与其它的定义相冲突。
例如
define("A_GLOBAL_CONSTANT", "Hello world!");
静态变量
? 静态变量应该带前缀‘s’。
理由
? 知道一个变量的作用域是非常重要的。
例如
function test()
{
static $msStatus = 0;
}
引用变量和函数返回引用
? 引用必须带‘r’前缀
理由
? 使得类型不同的变量容易辨认
? 它可以确定哪个方法返回可更改对象,哪个方法返回不可更改对象。
例如
class Test
{
var mrStatus;
function DoSomething(&$rStatus) {};
function &rStatus() {};
}
2.书写注释
类的注释
/**
* @ Purpose:
* 访问数据库的类,以ODBC作为通用访问接口
* @Package Name: Database
* @Author: Forrest Gump gump@crtvu.edu.cn
* @Modifications:
* No20020523-100:
* odbc_fetch_into()参数位置第二和第三个位置调换
* John Johnson John@crtvu.edu.cn
* @See: (参照)
*/
class Database
{
……
}
方法注释
/**
* @Purpose:
* 执行一次查询
* @Method Name: Query()
* @Parameter: string $queryStr SQL查询字符串
* @Return: mixed 查询返回值(结果集对象)
*/
function($queryStr){……}
属**或变量注释
/**
* @Purpose:
* 数据库连接用户名
* @Attribute/Variable Name: mDbUserName
* @Type: string
*/
var mDbUserName
if (0)来注释外部代码块
有时需要注释大段的测试代码,最简单的方法就是使用if (0)块:
function example()
{
great looking code
if (0) {
lots of code
}
more code
}
3.书写规则
见全文
4.帮助与共享
见全文
5.其他
见全文
全文地址
http://www.phpchina.cn/jiaocheng/html/supter/2006/0531/110.html
Apache环境下 url_rewrite配置
Posted in Linux/Apache on 2006/10/12 / 评论(3) »
Apache环境下DZ论坛url_rewrite配置
url_rewrite有什么好处?
当然有,输出.html格式有利于搜索引擎收录。
我今天才开始弄,在网上找了相关资料,没找到,经童虎指点
在几次修改、测试的情况下终于成功
演示:(暂无)
首页:http://www.todayit.com.cn/index.html
其他还有很多,大家可以随意设置哪个动态页url_rewrite
首先你的服务器得支持url_rewrite和.htaccess,否则请按照如下设置
一、设置httpd.conf文件
1、删除以下两行前的注释#
QUOTE:
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c
2、使APACHE支持.htaccess
QUOTE:
#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks MultiViews
#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride All 将none改成ALL
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
我的.htaccess文件如下:
CODE:[Copy to clipboard]RewriteEngine On
RewriteBase /
RewriteRule ^archiver/([a-z0-9\-]+\.html)$ $1/archiver/index.php?$2
RewriteRule ^index.html$ $1/index.php?sid=$2
RewriteRule ^(.*)digest.html$ $1/digest.php
RewriteRule ^(.*)thread-([0-9]+)\.html$ $1/viewthread.php?tid=$2
RewriteRule ^(.*)forum-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2
RewriteRule ^(.*)forum-([0-9]+)\.html$ $1/forumdisplay.php?fid=$fup[fid]
RewriteRule ^(.*)thread-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&page=$3&fpage=$4
RewriteRule ^(.*)forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)forum-([0-9]+)-([a-z0-9\-]+)\.html$ $1/forumdisplay.php?fid=$2&filter=$3
RewriteRule ^(.*)thread-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?fid=$2&tid=$3&action=printable
目前我只设置这么多,大家需要可以自己设置
RewriteBase /为目录,如果是/bbs则设置为RewriteBase /bbs
RewriteRule ^index.html$ $1/index.php?sid=$2
这样用户访问index.html时就映射到了index.php上
同样
RewriteRule ^(.*)forum-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2
当用户访问forum-数字.html时候就映射到了forumdisplay.php?fid=$2
其中$2为传递版面ID变量
这样做好了模板还需要做相应修改,比如forum-1.html可以访问$fd=1的版面,那么我们将相应的forumdisplay.php?fid=$fid连接改为forum-$fid.html就可以了
其实很简单,甚至可以将所有页面url_rewrite化,不过我只做这几个页。主要是为了收录帖子。其他还是动态页。大家可以参考以上代码url_rewrite其他页面。
最后记得.htaccess文件2进制上传,属性644
===================================
Zeus规则
DZ参考
CODE:[Copy to clipboard]match URL into $ with ^(.*)/archiver/([a-z0-9\-]+\.html)$
if matched then
set URL = $1/archiver/index.php?$2
endif
match URL into $ with ^(.*)/forum-([0-9]+)-([0-9]+)\.html$
if matched then
set URL = $1/forumdisplay.php?fid=$2&page=$3
endif
match URL into $ with ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$
if matched then
set URL = $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3
endif
match URL into $ with ^(.*)/profile-(username|uid)-(.+?)\.html$
if matched then
set URL = $1/viewpro.php?$2=$3
endif
有关url_rewrite更多资料:http://www.discuz.net/viewthread.php?tid=208240
url_rewrite有什么好处?
当然有,输出.html格式有利于搜索引擎收录。
我今天才开始弄,在网上找了相关资料,没找到,经童虎指点
在几次修改、测试的情况下终于成功
演示:(暂无)
首页:http://www.todayit.com.cn/index.html
其他还有很多,大家可以随意设置哪个动态页url_rewrite
首先你的服务器得支持url_rewrite和.htaccess,否则请按照如下设置
一、设置httpd.conf文件
1、删除以下两行前的注释#
QUOTE:
LoadModule rewrite_module modules/mod_rewrite.so
AddModule mod_rewrite.c
2、使APACHE支持.htaccess
QUOTE:
#
# This may also be "None", "All", or any combination of "Indexes",
# "Includes", "FollowSymLinks", "ExecCGI", or "MultiViews".
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
Options Indexes FollowSymLinks MultiViews
#
# This controls which options the .htaccess files in directories can
# override. Can also be "All", or any combination of "Options", "FileInfo",
# "AuthConfig", and "Limit"
#
AllowOverride All 将none改成ALL
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
我的.htaccess文件如下:
CODE:[Copy to clipboard]RewriteEngine On
RewriteBase /
RewriteRule ^archiver/([a-z0-9\-]+\.html)$ $1/archiver/index.php?$2
RewriteRule ^index.html$ $1/index.php?sid=$2
RewriteRule ^(.*)digest.html$ $1/digest.php
RewriteRule ^(.*)thread-([0-9]+)\.html$ $1/viewthread.php?tid=$2
RewriteRule ^(.*)forum-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2
RewriteRule ^(.*)forum-([0-9]+)\.html$ $1/forumdisplay.php?fid=$fup[fid]
RewriteRule ^(.*)thread-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?tid=$2&page=$3&fpage=$4
RewriteRule ^(.*)forum-([0-9]+)-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2&page=$3
RewriteRule ^(.*)forum-([0-9]+)-([a-z0-9\-]+)\.html$ $1/forumdisplay.php?fid=$2&filter=$3
RewriteRule ^(.*)thread-([0-9]+)-([0-9]+)\.html$ $1/viewthread.php?fid=$2&tid=$3&action=printable
目前我只设置这么多,大家需要可以自己设置
RewriteBase /为目录,如果是/bbs则设置为RewriteBase /bbs
RewriteRule ^index.html$ $1/index.php?sid=$2
这样用户访问index.html时就映射到了index.php上
同样
RewriteRule ^(.*)forum-([0-9]+)\.html$ $1/forumdisplay.php?fid=$2
当用户访问forum-数字.html时候就映射到了forumdisplay.php?fid=$2
其中$2为传递版面ID变量
这样做好了模板还需要做相应修改,比如forum-1.html可以访问$fd=1的版面,那么我们将相应的forumdisplay.php?fid=$fid连接改为forum-$fid.html就可以了
其实很简单,甚至可以将所有页面url_rewrite化,不过我只做这几个页。主要是为了收录帖子。其他还是动态页。大家可以参考以上代码url_rewrite其他页面。
最后记得.htaccess文件2进制上传,属性644
===================================
Zeus规则
DZ参考
CODE:[Copy to clipboard]match URL into $ with ^(.*)/archiver/([a-z0-9\-]+\.html)$
if matched then
set URL = $1/archiver/index.php?$2
endif
match URL into $ with ^(.*)/forum-([0-9]+)-([0-9]+)\.html$
if matched then
set URL = $1/forumdisplay.php?fid=$2&page=$3
endif
match URL into $ with ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$
if matched then
set URL = $1/viewthread.php?tid=$2&extra=page\%3D$4&page=$3
endif
match URL into $ with ^(.*)/profile-(username|uid)-(.+?)\.html$
if matched then
set URL = $1/viewpro.php?$2=$3
endif
有关url_rewrite更多资料:http://www.discuz.net/viewthread.php?tid=208240




