2012年12月26日星期三

PHPCMS V9系统类库与函数库调用


PHPCMS V9系统类库与函数库调用


系统类库位于系统的phpcms/libs/classes目录下面,函数库文件名为*.class.php,其中global.func.php为框架中默认加载,global.func.php中函数可直接使用
系统函数库位于系统的phpcms/libs/functions目录下面,函数库文件名为*.func.php
系统类库调用
/**
 * 加载系统类方法
 * @param string $classname 类名
 * @param string $path 扩展地址
 * @param intger $initialize 是否初始化
 */
 public static function load_sys_class($classname, $path = '', $initialize = 1) {
   return self::_load_class($classname, $path, $initialize);
 }
示例:
$http = pc_base::load_sys_class('http'); //实例化http类
pc_base::load_sys_class('format', '', 0); //调用form类,不进行实例化操作
系统函数库调用
/**
 * 加载系统的函数库
 * @param string $func 函数库名
 */
 public static function load_sys_func($func) {
   return self::_load_func($func);
 }
示例:
pc_base::load_sys_func('mail'); 调用mail函数包

Linux服务器上安装Sphinx教程


Linux服务器上安装Sphinx教程


1.下载源码包 http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
$ tar xzvf sphinx-0.9.8.tar.gz
$ cd sphinx
$ ./configure --prefix=/usr/local/sphinx --with-mysql=/usr/local/mysql
$ make
$ make install
常见问题1
/usr/local/sphinx-0.9.9/src/sphinx.cpp:20060: undefined reference to `libiconv_open'
/usr/local/sphinx-0.9.9/src/sphinx.cpp:20078: undefined reference to `libiconv'
/usr/local/sphinx-0.9.9/src/sphinx.cpp:20084: undefined reference to `libiconv_close'
collect2: ld returned 1 exit status
make[2]: *** [indexer] Error 1
make[2]: Leaving directory `/home/jling/sphinx-0.9.9/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/jling/sphinx-0.9.9/src'
make: *** [all-recursive] Error 1
解决办法:打开configure文件,找到“#define USE_LIBICONV 1”,将注释去掉,并将1改成0。
常见问题2
error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory
解决办法:
64位系统ln -s /usr/local/webserver/mysql/lib/mysql/libmysqlclient.so.16.0.0 /usr/lib64/libmysqlclient.so.16
32位系统ln -s /usr/local/webserver/mysql/lib/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so.16

Windows上安装Sphinx全文索引服务


Windows上安装Sphinx全文索引服务


在Windows上安装sphinx
1.下载支持mysql的包 http://www.sphinxsearch.com/downloads/sphinx-0.9.9-win32.zip
2.解压缩 sphinx-0.9.9-win32.zip 到 D:sphinx
3.安装sphinx服务,在命令行执行命令
D:sphinxsearchd --install --config d:sphinxsphinx.conf --servicename SphinxSearch

PHPCMS V9开启MySQL数据库全文索引


PHPCMS V9开启MySQL数据库全文索引


很多网友在全站搜索时遇到搜一个字能搜出结果,搜词反而无结果的情况。
大多数是由于mysql未开启全文索引引起 ,mysql开启全文索引方法:
1、修改mysql配置文件:window服务器为my.ini,linux服务器为my.cnf,在 [mysqld] 后面加入一行“ft_min_word_len=1”,然后重启Mysql。
2、登录后台,模块->全站搜索->重建索引 重建全文索引。

PHPCMS V9二次开发技巧


PHPCMS V9二次开发技巧


如果要对已存在的控制器进行二次开发,为了方便升级不建议直接对内核文件直接修改该,您可以通过"MY_*.php"的形式进行二次开发。
例如您要对改phpcms/mood/index.php进行二次开发。您可以在与index.php同级的目录下建立"MY_index.php" 
MY_index.php代码如下
<?php
  class MY_index extends index{
     function __construct() {
       parent::__construct();
     }
    ……your code
 }
这样当您通过url访问index控制器的时候,系统会默认指向MY_index.php 并且原文件的方法将被继承,可以直接使用。

PHPCMS V9开放框架中配置文件的调用


PHPCMS V9开放框架中配置文件的调用


PHPCMS V9开放框架中配置文件配置在caches/configs/目录下。
配置文件调用:使用 load_config方法
 /**
                  * 加载配置文件
                  * @param string $file 配置文件
                  * @param string $key  要获取的配置荐
                  * @param string $default  默认配置。当获取配置项目失败时该值发生作用。
                  * @param boolean $reload 强制重新加载。
                  */
                 public static function load_config($file, $key = '', $default = '', $reload = false) {
                    static $configs = array();
                    if (!$reload && isset($configs[$file])) {
                       if (empty($key)) {
                         return $configs[$file];
                       } elseif (isset($configs[$file][$key])) {
                         return $configs[$file][$key];
                       } else {
                         return $default;
                       }
                    }
                   $path = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.$file.'.php';
                   if (file_exists($path)) {
                     $configs[$file] = include $path;
                   }
                   if (empty($key)) {
                     return $configs[$file];
                   } elseif (isset($configs[$file][$key])) {
                     return $configs[$file][$key];
                   } else {
                     return $default;
                   }
                 }

示例:
调用系统配置中的附件路径
$upload_url = pc_base::load_config('system','upload_url');

PHPCMS V9二次开发中应该遵循的命名规范


PHPCMS V9二次开发中应该遵循的命名规范


PHPCMS其自身的一定规范。下面是使用PHPCMS做二次开发中应该遵循的命名规范:
  • 类文件需要以.class.php为后缀(这里是指的phpcms的系统类库文件和模块中的类库文件,第三方引入的不做要求),例如http.class.php。
  • 函数文件需要以.func.php为后缀(第三方引入的不做要求),例如mail.func.php。
  • 类名和文件名一致,例如 phpcmsapp类的文件命名是phpcmsapp.class.php。
  • 数据模型需要以“数据表名称_model.class.php”为形式,类名称与文件名必须相同。