Archive for the ‘php’ Category

安装pear所有包

找到一个文:http://www.karakas-online.de/forum/viewtopic.php?t=1385

内容我翻译了一下:

Question 问题:你需要在本地的php系统中安装所有的pear模块。也许你是一个需要全部模块的开发者。也许在尝试不同的模块,所以一次性的全部安装完是很有必要的,也许你需要查看他们的源代码,也许你需要是不是的安装一个新的pear模块。
一次性的安装和下载所有的pear模块原因很多,但官方并没有给出解决方案。Sad
我搜索了很久都没有发现任何一个单独的tar.gz或者zip包可以一键安装所有的pear模块库。
pear开发者之所有这样做,也许是因为带宽问题、也许他们不想让你的系统加载一些根本不需要的模块。
也或许这样使你像恨perl一样的恨php,因为那永无止境的模块安装。每次你都会热衷于一件事情-运行模块安装脚本。
高兴的是,如果你在linux下面工作:
Arrow解决方案:我假设你运行的php > 4.3.0 , 那么默认pear已经安装。为了一次性下载所有的pear包,你首先得得到一个安装列表:

Code:
pear remote-list | awk ‘{print $1}’ > pear-list

然后手动编辑pear-list,因为你需要手动的删除头两行文字,搞定。
现在输入

Code:
cat pear-list | xargs -n 1 pear install

一些包可能无法安装,需要再运行一次上面的命令:

Code:
cat pear-list | xargs -n 1 pear install

You may not manage to get them all installed (this depends on the versions of your installed components), but you will at least have 99% of them – and that’s enough for the start. Wink
你可能并没有安装完所有的 包(依赖于你安装模块的 版本),但至少至少安装了99%,对起步来说已经够了。
———————-(翻译完)

其实这个方法同样适合安装在windows平台的pear使用 ,windows平台默认没有 xargs awk 这些牛x的工具,这个时候我想到了cygwin。下载安装cygwin,通过awk得到包列表的命令是一样的,假设列表我放在c:\remote-list2 ,pear.bat在D:\phpnow\php-5.2.10-Win32\pear.bat,打开cygwin执行:

cat /cygdrive/c/remote-list2 | xargs -n 1 /cygdrive/d/phpnow/php-5.2.10-Win32/pear.bat install -fa

我发现加上fa两个参数,可以下载更多的包,参数解释:

-f, –force
will overwrite newer installed packages(强制安装)

-a, –alldeps
install all required and optional dependencies(自动安装有被依赖的包)

 

pear安装

如果你需要用php写一个系统,coding from scratch不是很现实,如果你追求效率,那么使用已经写好的php类绝对是不二的选择。我今天就安装了最牛逼玩意儿,pear!

啥是pear呢?

PEAR is short for “PHP Extension and Application Repository” and is pronounced just like the fruit. The purpose of PEAR is to provide:

  • A structured library of open-source code for PHP users
  • A system for code distribution and package maintenance
  • A standard style for code written in PHP, specified here
  • The PHP Extension Community Library (PECL), see more below
  • A web site, mailing lists and download mirrors to support the PHP/PEAR community

简单翻译一下PEAR是“PHP Extension and Application Reporsitory”的简称,也就是php扩展和程序库,发音和fruit一样,PEAR的目标是:

  • 成为php用户开源代码的类库
  • 一个用于包维护和代码分发的系统
  • php代码的一种标准风格
  • php扩展社区酷
  • 支持php/pear社区的一个网站、邮件列表、下载镜像

pear不光是类库,我觉得叫类库仓库比较适合,pear和linux系统上的apt或者yum类似,维护类库以及他们的依赖性。

我的环境是windows 7,php 5.2.10(D:\phpnow\php-5.2.10-Win32目录)

下载安装好php之后,需要手动运行go-pear.bat。

D:\phpnow\php-5.2.10-Win32>go-pear.bat

Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :

选择系统级别安装还是本地安装,默认system,直接回车

Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type ‘all’ to change all of them or simply press Enter to
accept these locations.  以下是默认的pear的临时、数据、配置、测试、执行目录的设置,默认回车

1. Installation base ($prefix)                   : D:\phpnow\php-5.2.10-Win32
2. Temporary directory for processing            : D:\phpnow\php-5.2.10-Win32\tmp
3. Temporary directory for downloads             : D:\phpnow\php-5.2.10-Win32\tmp
4. Binaries directory                            : D:\phpnow\php-5.2.10-Win32
5. PHP code directory ($php_dir)                 : D:\phpnow\php-5.2.10-Win32\pea
6. Documentation directory                       : D:\phpnow\php-5.2.10-Win32\doc
7. Data directory                                : D:\phpnow\php-5.2.10-Win32\dat
8. User-modifiable configuration files directory : D:\phpnow\php-5.2.10-Win32\cfg
9. Public Web Files directory                    : D:\phpnow\php-5.2.10-Win32\www
10. Tests directory                               : D:\phpnow\php-5.2.10-Win32\tes
11. Name of configuration file                    : C:\Windows\pear.ini
12. Path to CLI php.exe                           : D:\phpnow\php-5.2.10-Win32\.

1-12, ‘all’ or Enter to continue:
Beginning install…
Configuration written to C:\Windows\pear.ini…(pear配置文件默认写入到这里
Initialized registry…
Preparing to install…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.2.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.2.3.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.7.2.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.2.tar…
pear/PEAR can optionally use package “pear/XML_RPC” (version >= 1.4.0)
install ok: channel://pear.php.net/Archive_Tar-1.3.2
install ok: channel://pear.php.net/Console_Getopt-1.2.3
install ok: channel://pear.php.net/Structures_Graph-1.0.2
install ok: channel://pear.php.net/PEAR-1.7.2
PEAR: Optional feature webinstaller available (PEAR’s web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR’s PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR’s PHP-GTK2-based installer)
PEAR: To install optional features use “pear install pear/PEAR#featurename”

↑然后直接通过默认的channel:pear.php.net 开始直接下载安装pear了,这些包是默认初始化安装的,之后可以添加、删除、更新。

******************************************************************************
WARNING!  The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<D:\phpnow\php-5.2.10-Win32\pear>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.

Current include path           : .;C:\php5\pear
Configured directory           : D:\phpnow\php-5.2.10-Win32\pear
Currently used php.ini (guess) :
Press Enter to continue:

接下来,需要将pear配置目录D:\phpnow\php-5.2.10-Win32\pear加入php.ini的include_path指令中。打开php.ini跳转到include_path,每个路径使用分号分隔,.表示当前目录,所以:

include_path = “.;d:\phpnow\php-5.2.10-Win32\PEAR”

然后重新启动apache,让php.ini的修改生效。

** WARNING! Old version found at D:\phpnow\php-5.2.10-Win32, please remove it or be sure to use the new d:\phpnow\php-5.2.10-win32\pear.bat command

The ‘pear’ command is now at your service at d:\phpnow\php-5.2.10-win32\pear.bat

然后可以通过pear.bat命令来对pear系统进行各种管理。
* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under D:\phpnow\php-5.2.10-Win32\PEAR_ENV.reg .
This file creates ENV variables for the current user.

Double-click this file to add it to the current user registry.

运行php目录下的PEAR_ENV.reg将PEAR的各种目录加入环境变量中。

接下来需要测试pear时候已经安装成功,新建一个php文件,写入内容:

1
2
equire_once 'System.php';
var_dump(class_exists('System'));

如果页面返回 bool(true) 表明安装成功。

一些常用的pear命令
安装包
  pear install packagename

下载包,但不安装
  pear download packagename
  pear download-all

安装已经下载的包
  pear install filename.tgz

列出channel里面所有的包
  pear remote-list

列出已经安装的包
  pear list

列出可升级的包
  pear list-upgrades

更新包
  pear upgrade packagename
  pear upgrade-all

删除包
  pear uninstall packagename

就大概说到这里,感兴趣的可以转移到官方网站了解详情,下载一个手册也够你看1年的了,囧。

主页:http://pear.php.net/

文档:http://pear.php.net/manual/

bugs:http://pear.php.net/bugs/

 

Zend.Studio.v7.1.0-iNViSiBLE.rar下载

测试可用。
下载地址:http://hotfile.com/dl/19985653/a38f93f/Zend.Studio.v7.1.0-iNViSiBLE.rar.html

 

php open_basedir

在php写了句require_once ‘../Zend/Loader.php’; 报错:

Warning: require_once() [function.require-once]: open_basedir restriction in effect. File(../Zend/Loader.php) is not within the allowed path(s): (D:\phpnow\vhosts\zf.com;C:\Windows\Temp;) in D:\phpnow\vhosts\zf.com\index.php on line 6

Warning: require_once(../Zend/Loader.php) [function.require-once]: failed to open stream: Operation not permitted in D:\phpnow\vhosts\zf.com\index.php on line 6

Fatal error: require_once() [function.require]: Failed opening required '../Zend/Loader.php' (include_path='D:\phpnow\vhosts\zf.comZend;.;C:\php5\pear') in D:\phpnow\vhosts\zf.com\index.php on line 6

字面分析是受到了open_basedir的限制,造成Operation not permitted(操作不被允许)。

打开php.ini跳转到open_basedir相关设置段落:

; open_basedir, if set, limits all file operations to the defined directory
; and below.  This directive makes most sense if used in a per-directory
; or per-virtualhost web server configuration file. This directive is
; *NOT* affected by whether Safe Mode is turned On or Off.
;open_basedir =

如果设置了open_basedir,那么所有能被操作的文件就只能限制在open_basedir指定的目录里面。

这个在虚拟主机里面这个指令相当有用。不管安全模式是否打开,这个指令都不受影响。

看来php.ini没有设置open_basedir。

打开apache虚拟主机配置文件:

1
2
3
4
5
6
7
8
9
10
11
<VirtualHost *>
    <Directory "../vhosts/zf.com">
        Options -Indexes FollowSymLinks
    </Directory>
    ServerAdmin admin@zf.com
    DocumentRoot "../vhosts/zf.com"
    ServerName zf.com:80
    ServerAlias *.zf.com
    ErrorLog logs/zf.com-error_log
    php_admin_value open_basedir "D:\phpnow\vhosts\zf.com;C:\Windows\Temp;"
</VirtualHost>

里面的php_admin_value open_basedir就限定了操作目录。
我这里是本地测试,安全因素不考虑,直接将 php_admin_value open_basedir “D:\phpnow\vhosts\zf.com;C:\Windows\Temp;” 删除掉,重新启动apache,ok。

 

jquery.treeview插件绑定数据库(php+oracle)

公司的HOA系统有个人员组织选定的功能,用的是MzTreeView这个js库,后台的人员信息表也是根据MzTreeView来设计的,也就是任意一条记录有一个id来唯一标识这条记录和一个parentId来记录它的父节点。

mztreeview

最近在学习jquery,找到了很多实用的插件,比如今天要说的是jquery.treeview

打算将jquery.treeview插件绑定到数据库,从数据库中取数据,用的脚本是php,后台数据库将就系统本来的oracle。

在功能上其实mztreeview比jquery.treeview要强大一些,效率还高点。唯一好点就是js压缩后只有6k,而mztreeview有20多k。总之没事干,just 4 fun。

表结构:

Name Type Nullable Default Comments
————- ————- ——– ——- ——–
ID_ROLE NUMBER(10)
CHAR_ROLENAME NVARCHAR2(30)
INT_ROLETYPE NUMBER(10)
ID_UPLEVEL NUMBER(10)
CHAR_REMARK VARCHAR2(50) Y
B_DELETE NUMBER(2)
INT_ORDER NUMBER(10) Y
DEPT_CODE NVARCHAR2(30) Y ’se’

ID_ROLE是unique id,ID_UPLEVEL是parent id。

jquery下载下来之后,解压放到web目录,然后把下面的脚本文件放入demo目录。
php脚本如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <meta http-equiv="content-type" content="text/html; charset=gb2312"/>
    <title>treeview test on hoa</title>
   
    <link rel="stylesheet" href="../jquery.treeview.css" />
    <link rel="stylesheet" href="../red-treeview.css" />
    <link rel="stylesheet" href="screen.css" />
   
    <script src="../lib/jquery.js" type="text/javascript"></script>
    <script src="../lib/jquery.cookie.js" type="text/javascript"></script>
    <script src="../jquery.treeview.js" type="text/javascript"></script>
   
    <script type="text/javascript">
    $(document).ready(function(){
        $("#browser").treeview({  //调用jquery.tree的代码
            collapsed:true,  //默认把组织树收缩起来
        });
    });
    </script>
    </head>
    <body>
   
    <h1 id="banner"> Demo</h1>
    <div id="main">
    <ul id="browser" class="treeview-red">
    <?php

function read($uplevel){ //递归函数,用来遍历树
    $conn = oci_connect('ora_user', 'ora_pass', 'orcl');  
    if(!$conn)
    {
        print ("conn error");
    }
    $query = "SELECT * FROM sa_role where id_uplevel=".$uplevel." and b_delete='0' order by id_role";
    //echo $query;
    $stid = oci_parse($conn, $query);

    $r = oci_execute($stid, OCI_DEFAULT);
    while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS))
    {  
        if($row[2]==2) //$row[2]是INT_ROLETYPE,2是下面有子节点,1是叶子(就是没有子节点的节点)
        {  
            print "<li> <span class=\"folder\">";
            print $row[1]."</span> \n"; //$row[1]是节点内容,这个字段是CHAR_ROLENAME
            print "\n\t<ul>";
            $uplevel=$row[0];
            read($uplevel); //再调用自己继续读节点
        }
        if($row[2]==1) //如果是叶子
        {  
           
            print "<li> <span class=\"file\">";
            print $row[1]."</span> ";
            print "</li>";  
        }
    }
    print "</ul>";
    oci_close($conn);
}
read(-1);//假设根节点id为-1
print "</li>";
?>
    </ul>  
    </div>
 
</body></html>

其中修改

1
<ul id="browser" class="treeview-red">

中class的值为treeview-red,treeview-default,treeview-black,treeview-gray,treeview-famfamfam,这些是jquery.treeview自带的样式。

可以在

1
2
        $("#browser").treeview({  
        });

中,可以加入参数自定义,具体参数用法参照:http://docs.jquery.com/Plugins/Treeview/treeview#options
参数解释:
animated: “fast” 树的展开速度为快
collapsed: true 收缩树的所有节点
unique: true 保持每次展开1个节点,关闭之前打开的兄弟节点
persist: “location” 把进入的节点位置通过url保存

1
2
3
4
        branches = $("<li class='closed'><span class='folder'>New Sublist</span><ul><li><span class='file'>Item1</span></li><li><span class='file'>Item2</span></li></ul></li>").prependTo("#folder21");
        $("#browser").treeview({
            add: branches
        });

插入新节点

persist: “cookie” 把进入的节点位置通过cookie保存,需要jquery插件jquery.cookie.js
cookieId: “treeview-black” 设置cookie名
control: “#treecontrol” 把树的控制交给id为treecontrol

toggle: function() {
window.console && console.log(“%o was toggled”, this);
}
设定一个交替函数

———
最后效果:
jquery.treeview.demo

这里只做到了树的查看,还有有些问题需要解决,比如节点插入,删除,编辑与数据库的交互,貌似需要用到牛逼的ajax。

 

dedecms栏目转换为单页

本文使用的是dedecms的版本是5.5,模板是默认的default模板。
dedecms的栏目管理功能是很强大的,在一些企业网站中,需要“企业简介”、“联系我们”这类的单页。dedecms也专门增加了“栏目内容”功能:

category_manage

说明:栏目内容是替代原来栏目单独页的更灵活的一种方式,可在栏目模板中用{dede:field.content/}调用,通常用于企业简介之类的用途。

方法如下:
进入你需要将栏目修改为单页的栏目。进入“栏目内容”标签,添加内容为你的单页所展示的内容。

然后进入“高级选项”,将列表模板修改为{style}/artile_cat_to_single.htm。

然后新建一个模板页面artile_cat_to_single.htm放在模板目录。内容直接从default模板的article_article.html复制过来。

然后定位到“field.body”,将“field.body”改为“field.content”。

别忘了“更新栏目缓存”,F5刷新一下就搞定了。

关键是“field.content”放到你希望的位置就可以了。

还要注意的是编辑自己的模板页编码方式(utf8 or gb2312?)一定要和自己dedecms系统一致,否则会出现乱码。

dedecms utf8的编码是:UTF-8无BOM格式编码。

 

配置smarty开发环境

首先到 http://www.smarty.net 上下载最新的smarty模板引擎,解压Smarty-2.6.26.zip,改名Smarty-2.6.26目录为smarty。

拷贝smarty目录到你希望的目录 D:\xampp\xampp\smarty。

在php.ini的include_path加入smarty库目录,如下:

include_path = “.;D:\xampp\xampp\php\PEAR;D:\xampp\xampp\smarty\libs”

在你的php项目目录新建两个子目录放配置文件和模板:config 和templates

D:\xampp\xampp\htdocs\config

D:\xampp\xampp\htdocs\templates

smarty项目目录新建两个目录cache和templates_c存放缓存和编译过的模板:

D:\xampp\xampp\smarty\cache

D:\xampp\xampp\smarty\templates_c

在需要调用smarty库的php文件中写入代码:

1
2
3
4
5
6
7
8
9
10
11
//this is D:\xampp\xampp\htdocs\index.php
//load smarty library
require('Smarty.class.php');

$smarty=new Smarty();
$smarty->template_dir='d:/xampp/xampp/htdocs/templates'; //指定模板存放目录
$smarty->config_dir='d:/xampp/xampp/htdocs/config';//指定配置文件目录
$smarty->cache_dir='d:/xampp/xampp/smarty/cache';//指定缓存目录
$smarty->compile_dir='d:/xampp/xampp/smarty/templates_c';//指定编译后的模板目录
$smarty->assign('name','fish boy!');
$smarty->display('index.tpl');

再新建一个D:\xampp\xampp\htdocs\templates\index.tpl文件

1
2
3
4
5
6
7
8
9
10
<html>
<head><title>hello,{$name}!</title>
<script language="javascript" type="text/javascript">
    alert('{$name}');
</script>
</head>
<body>
hello,{$name}!
</body>
</html>

打开http://localhost/index.php 应该会弹出fish boy!警告,然后内容为hello,fish boy!!的页面。
我们可以改进一下,不可能每次需要smarty写这么多配置代码吧。
新建文件 D:\xampp\xampp\htdocs\smarty_connect.php

1
2
3
4
5
6
7
8
9
10
11
//load smarty library
require('Smarty.class.php');
class smarty_connect extends Smarty
{   function smarty_connect()
    {//每次构造自动调用本函数
        $this->template_dir='d:/xampp/xampp/htdocs/templates';
        $this->config_dir='d:/xampp/xampp/htdocs/config';
        $this->cache_dir='d:/xampp/xampp/smarty/cache';
        $this->compile_dir='d:/xampp/xampp/smarty/templates_c';
    }
}

D:\xampp\xampp\htdocs\index.php改为:

1
2
3
4
    require('smarty_connect.php');
    $smt=new smarty_connect;
    $smt->assign('name','fish boy!');
    $smt->display('index.tpl');

index.tpl文件不变,打开localhost/index.php,出现了同样的输出。

 

第二个单位的面试

昨天接到通知,今天下午2点钟去面试。面试的单位是重庆本地的百脑汇威客网,地址在观音桥远东百货对面的海逸花园B栋2005,上午10点钟就出发了,在杨家坪吃完午饭也差不多刚好下午1点40到达。

貌似那个不算是写字楼,就住宅。进门的那个美女把我认出来了,知道我是陈家坪招聘会的那个应聘者。这个单位从规模来看,100平方的地,员工10多人。面试我的估计又是技术部门的,口头问了一些问题,全是技术方面的。终于验证了我的想法,搞技术的还是得靠水平,而不是靠其他。我寝室的一哥们,理想是职业经理人,简历重点花在了琢磨编出一些华丽的辞藻来组成一封有气势的自荐信,我自我感觉这个没多大作用,华而不实的东西很少人去细看。所以我没有写那个自荐信,就算是写了我也得边写边抱怨写这玩意儿干啥。

主要问到的问题有,php及其oop了解程度、有无开发案例、有无大型网站开发经验缓存数据表优化、seo、框架模板、div+css布局、版本控制。红色字体是我现在所缺乏的,还有我是否有必要学习美工方面的知识呢,比如photoshop,网站ui,哥可没有美术基础啊,美术水平尚停留在“小鸡吃米图”的境界。

最后的答复是再商量,我感觉又泡汤了,囧,还有半年毕业了哦。。。

还在继续咳嗽,要出人命了。

 

感冒、手关节痛、找工作、将来半年内打算

10月25日去了陈家坪技术展览中心,干嘛呢?找工作!

说老实话,这还是我第一次参加招聘。之前没有任何兼职、招聘、面试的经验。我怀着打探的心态去嘹望了一下。简历是我一天前刚出炉的。

resume_resize

花个10大洋门票进了会场,发现房地产和制造业非常多也很火爆啊。我猜想都是房地产的原因。我想找的职位是网站程序员,说牛逼点也可以叫网站工程师。全部都找了一遍,发现了4个招php程序员的,还有1个unix系统管理员。都填了表,目前只有银贝公关去面试了来,听说他们在做库购网,还和重庆有限合作搞数字电视方面的业务,貌似很不错的样子。但是最后没有谈定,面试我的是技术部经理,最后给的回复是和总经理再商量一下。我感觉比较悬,很像是委婉的拒绝。其实俺现在也无所谓啦,毕竟是应届毕业生,没啥经验。别个需要的是你来就可以上岗那种,不需要任何培训的。自己打算在以后的这半年多积累一些开发经验,多熟悉一些框架方面的东西,接点案子、项目来做,最好能找个能做网站美工的和我合伙。那估计以后求职路兴许会更加的平坦。

已经感冒1个星期了,但是也不知道是不是感冒,反正没有发烧。只是咳嗽。难受啊,吃药都吃了好几天了,这几天状态真的不是很好,被这个病给折磨的。所以我决定以后安排好自己的作息时间,不开夜车了。晚上最迟1点钟睡觉,早上9点钟以前起床。

现在每个星期还有两节课,我也不想听了。因为没意思,也没用。最多就是考试挂科,俺也无所谓。

明天得赶在中午饭之前回家,得调养一下,吃好点。在学校,都不知道一天是吃啥玩意儿度日的。

生活嘛,就是一个字———-混。

 

PHP5 面向对象初步.pdf下载

这个星期把这本书看完了。

phpchina的刀客羽朋写的,有5章,讲的比较有趣,每个例子都有在zend studio下面的运行裁图。

下载地址:

http://4u3w.net/books/down.aspx?id=1049