php

cakephp 多库连接 Missing Database Table错误

cakephp的代码,放到服务器上就报“Missing Database Table”错。
Missing Database Table

Error: Database table sipusers for model Sipuser was not found.

Notice: If you want to customize this error message, create app/views/errors/missing_table.ctp

在本地运行的好好的,这个比较晕。

经过测试,修改,把服务器上的Sipuser.php文件名改为小写。把$useTable变量的表名也改为:var $useTable = 'subscriber';。这样就可以了。

其他$default配置中的表也有同样的问题。呵呵,其他几个文件我是用cake bake生成的。

主要是大小写不匹配的问题。欢迎大家讨论。

附上多库连接的方法:

1、database.php中新建一个连接配置。
2、model中使用使用如下方法引入即可:
var $useDbConfig = 'sipdb';
var $useTable = 'subscriber';

控制PHP中递归的次数示例

private function Generate($min = 600000, $max = 700000) {
global $conn, $tbl_users;
static $depth = 0;

if ($depth > 3) {
return FALSE;
}
$depth ++;
$userid = mt_rand ( $min, $max );

$query = "SELECT `userid` FROM {$tbl_users} WHERE userid='{$userid}' LIMIT 1;";
if (FALSE != ($result = mysql_query ( $query, $conn ))) {
if (mysql_num_rows ( $result ) < 1) {
mysql_free_result ( $result );
} else {
mysql_free_result ( $result );
$this->Generate ( $min, $max );
}
} else {

使用DreamweaverCS4编辑Cakephp的CTP文件

使用DreamweaverCS4编辑Cakephp的CTP文件示例:

  1. 打开文件C:\Documents and Settings\Administrator\Application Data\Adobe\Dreamweaver CS4\en_US\Configuration\Extensions.txt。

    我装的是WindowsXP + Adobe Design CS4,英文版,所以是这个路径。其它系统版本路径分别是:
    • Dreamweaver CS3 on Windows Vista:

      C:\Users\[username]\AppData\Roaming\Adobe\Dreamweaver 9\Configuration
    • Dreamweaver 8 on Windows Vista:

      C:\Users\[username]\AppData\Roaming\Macromedia\Dreamweaver 8\Configuration
    • Dreamweaver CS3 on Windows XP:

Poedit的使用

Poedit的使用

1、设置首选项

使Poedit支持Cakephp的*.ctp文件。

打开“文件”菜单,“首选项”,“解析器”,“新建立。”

使用CTP文件的解析器命令:

xgettext --language=PHP --force-po -o %o %C %K %F

没设置好会出现这样的错误:xgettext: warning: file ‘.ctp’ extension ‘ctp’ is unknown; will try C.

2、新建项目

打开“文件”菜单,“新建消息目录文档”,全进入设置对话框,

复数形式可设置为:nplurals=2; plural=n==1?0:1;
源文件编码可不设置,如果设置一定要设置正确,如utf-8。

路径设置为你的源代码路径:

关键字设置为函数名之类的即可,如图:

php执行如下代码,apache崩溃

装的是ApacheFriends XAMPP (Basispaket) version 1.7.1的组件。php执行如下代码,apache崩溃,原因未知。
<?php
function foo($str) {
static $i = 0;
print "$str : $i";
++ $i;
}

register_tick_function ( 'foo', 'count' );

declare ( ticks = 6 ) {
for($i = 0; $i < 20; ++ $i) {
echo "$i";
}
}
?>

WordPress的主题,三千个左右

2400个WordPress主题下载:
Yong3g.com_netps.cn_wpthemes.reup.rar

下载主题的站点
http://themes.wopus.org/

100个优秀的免费 WordPress 主题
http://jandan.net/2008/01/09/100-excellent-free-wordpress-themes.html

WordPress的插件使用-添加自定义社会标签到Sociable中

Adding a site to Sociable(添加自定义社会标签到Sociable中)
具体效果可查看:http://www.yong3g.com/

首先从http://yoast.com/wordpress/sociable/下载插件;
1. 下载16x16的图片到目录sociable/images/directory。
2. 打开 sociable.php。
3. 查找数组$sociable_known_sites。
4. Copy / paste the code for another site (they're in alphabetical order).
5. Change the value of favicon to the name of your image file.

偶用到的CURL函数

代码:
# $url = "http://www.netps.cn";
# $ch = curl_init();
# curl_setopt($ch, CURLOPT_URL, $url);
# curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

1、resource curl_init ( [string url])
The curl_init() will initialize a new session and return a CURL handle for use with the curl_setopt(), curl_exec(), and curl_close() functions. If the optional url parameter is supplied then the CURLOPT_URL option will be set to the value of the parameter. You can manually set this using the curl_setopt() function.

2、bool curl_setopt ( resource ch, string option, mixed value)

偶遇到的php函数

1、function nl2br($str)
功能:Inserts HTML line breaks before all newlines in a string
示例:<?php echo nl2br("foo isn't\n bar"); ?>
结果:\n会被HTML的换行替换

重定向状态代码

重定向可以被串联,老版本的RFC2616规定重定向最多不超过5次,一般使用时不要超过3次。

重定向状态代码
状态代码 描述 实现
300 多个选择  
301 永久转移 .htaccess:
RewriteRule ^foo\.php$ /bar.php [R=301,L]
或PHP(如果只有Location而没301状态,相当于302临时重定向):
header('HTTP/1.1 301 Moved Permanently');
header('Location:http://www.netps.cn/bar.php');