yaf配置通用函数

yaf配置通用函数
在Bootstrap.php中加载

/**
 * 通用函数配置
 */
public function _initCommonFunctions(){
//        \Yaf_Loader::import(\Yaf_Application::app()->getConfig()->app->root_path . '/library/common/functions.php');
    \Yaf_Loader::import(App::getConfig('app.root_path') . '/library/common/functions.php');
}

然后,在里面写通用的函数,就可以了!

<?php
/**
 * 通用函数库
 */
function test() {
    echo "test";
}

也可以引入类

/**
 * 通用函数配置
 */
public function _initCommonFunctions(){
    \Yaf_Loader::import(App::getConfig('app.root_path') . '/library/common/Func/Func.php');
}
<?php
namespace common\Func;

/**
 * 通用函数库
 */
class Func {
    /**
     * 上午下午
     */
    public static function test()
    {
        $no = date('H');
        $return = '您好';
        if ($no > 0 && $no <= 6) {
            $return = '凌晨好';
        }
        if ($no > 6 && $no < 12) {
            $return = '上午好';
        }
        if ($no >= 12 && $no <= 18) {
            $return = '下午好';
        }
        if ($no > 18 && $no <= 24) {
            $return = '晚上好';
        }
        return $return;
    }
}

使用

echo Func::test();

猜你喜欢

转载自www.cnblogs.com/jiqing9006/p/12110912.html
今日推荐