zoukankan      html  css  js  c++  java
  • 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 commonFunc;
    
    /**
     * 通用函数库
     */
    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();
    
  • 相关阅读:
    Java 在线/离线 文档
    Java集合框架全解
    【LeetCode】204.计数质数
    深入SpringMvc
    SpringMvc基础
    SSM整合
    Spring注解
    SpringAop编程
    2路插入排序
    Matplotlib绘图库简要介绍
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/12110912.html
Copyright © 2011-2022 走看看