index.php

<?php
/**
 * 调试模式
 */
define('APP_DEBUG',True);

// define('BIND_MODULE','Home');

/**
 * 项目设置
 */
define ( 'APP_PATH', './Application/' );

/**
 * 缓存目录设置,权限必须可写
 */
define ( 'RUNTIME_PATH', './Runtime/' );

/**
 * 引入 Thinkphp 核心库
 */
require './ThinkPHP/ThinkPHP.php';

Common > debug.php

<?php
return array(
    // 调试配置
    // 'SHOW_PAGE_TRACE' => true,
    /* 数据库配置 */
    'DB_TYPE'   => 'mysql', // 数据库类型
    'DB_HOST'   => '127.0.0.1', // 服务器地址
    'DB_NAME'   => 'guliangme', // 数据库名
    'DB_USER'   => 'root', // 用户名
    'DB_PWD'    => '',  // 密码
    'DB_PORT'   => '3306', // 端口
    'DB_PREFIX' => 'a_', // 数据库表前缀
/* 模板配置 */
'DEFAULT_THEME' => 'default',
);

Common > function.php

function friendly_date( $date ) {
    $sec  =  time() - $date;
    if ( $sec==0 ) {
        return '刚刚';
    } elseif ( $sec < 60 ) {
        return $sec .'秒前';
    } elseif ( $sec < 3600 ) {
        return round( $sec/60 ) . '分钟前';
    } elseif ( $sec <  86400 ) {
        return round( $sec/3600 ) .' 小时前';
    } elseif ( $sec < ( 86400*7 ) ) {
        return round( $sec/86400 ) . '天前';
    } elseif ( $sec< ( 86400*7*4 ) ) {
        return round( $sec/( 86400*7 ) ) .' 周前';
    }else {
        return date( "Y年n月d日", $date );
    }
}

/**
 * 字符串截取,支持中文和其他编码
 *
 * @static
 * @access public
 * @param string  $str     需要转换的字符串
 * @param string  $start   开始位置
 * @param string  $length  截取长度
 * @param string  $charset 编码格式
 * @param string  $suffix  截断显示字符
 * @return string
 */
function msubstr( $str, $start=0, $length, $charset="utf-8", $suffix=false ) {
    if ( function_exists( "mb_substr" ) )
        $slice = mb_substr( $str, $start, $length, $charset );
    elseif ( function_exists( 'iconv_substr' ) ) {
        $slice = iconv_substr( $str, $start, $length, $charset );
        if ( false === $slice ) {
            $slice = '';
        }
    }else {
        $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
        $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
        $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
        $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
        preg_match_all( $re[$charset], $str, $match );
        $slice = join( "", array_slice( $match[0], $start, $length ) );
    }
    return $suffix ? $slice.'...' : $slice;
}

Controller > CommonController.php

<?php
namespace Home\Controller;
use Think\Controller;

class CommonController extends Controller {

    public function _initialize (){

        /**
         * 获取配置项
         */
        if( false == $options = F('options') ){
            foreach( M('Options')->select() as $k => $v ) {
                $options[$v['name']] = $v['value'];
            }
            F('options',$options);
        }
        $this->assign('options',$options);

        /**
         * 读取导航条
         */
        if( false == $navs = F('navs') ){
            $navs = M('Navs')->order('view_sort DESC')->select();
            F('navs',$navs);
        }

        $this->assign('navs',$navs);
    }
}

GongChao
247 声望3 粉丝

自由人,个人主页:[链接] ,邮箱:ifeng1993@gmail.Com


引用和评论

0 条评论