Git Product home page Git Product logo

yaf_eloquent's Introduction

集成了 Laravel 的 Eloquent ORM 的 Yaf 框架

Supported PHP versions: >=5.4 Supported Yaf versions: >=1.8.0 Supported Eloquent versions: 5.0 License

Session由默认的文件改为Redis存储

public function _initSession()
{
    try {
        $redis = redisConnect();
        $redis->ping();
        $session = new Util_Session();
        session_set_save_handler($session, true);
    } catch (Exception $e) {
        Log_Log::info('[Bootstrap] session init error:' . $e->getMessage(), true, true);
    }
}

多个数据库链接操作如下


// 默认的
DB::table('tb_name')->get()

// another
DB::connection('another')->get();

文件上传

// 上传目录
$savePath = getConfig('upload', 'path');

// 允许的规则
$allowType = getConfig('upload', 'rule');

$result = parent::upload($allowType, $savePath);

邮件发送


# 首先安装sendmail模块
yum -y install sendmail  
/etc/rc.d/init.d/sendmail start

// 发送邮件,可群发
sendmail([
    'to'        => [], // 邮件发送人列表
    'cc'        => [], // 邮件抄送人列表
    'subject'   => '', // 邮件主题
    'content'   => '', // 邮件正文
    'attachment'=> []  // 附件列表
]);

数据加解密


$string = '数据加解密';
$crypt = new Util_CryptAES();
$crypt->set_key(getConfig('CryptAES', 'key'));
$crypt->require_pkcs5();

// 加密
$crypt_string = $crypt->encrypt($string);

// 解密
$decrypt_string = $crypt->decrypt($crypt_string); 

echo $crypt_string . ' ' . $decrypt_string; // 1MxgJsgKZKXXhTE8msOKpA== 数据加解密

// 此类还可以配合Java来进行加解密,具体链接可参考 http://www.cnblogs.com/yipu/articles/3871576.html

日志记录


// 直接记录在以日期开头的文件里,如16_08_24.log
Log_Log::info('this is a log', true, true);

// 加上前缀,prefix_16_08_24.log
Log_Log::info('this is a log', true, true, 'prefix');

Curl 操作


$curl = new \Http\Curl();

// get
$curl->get('https://www.example.com/search', array(
    'q' => 'keyword',
));

// post
$curl->post('https://www.example.com/login/', array(
    'username' => 'myusername',
    'password' => 'mypassword',
));

// more https://github.com/php-curl-class/php-curl-class

全局异常捕获


try {
    if ($_POST['test']) {
    
    }
} catch (Exception $e) {
    echo $e->getMessage(); // Undefined index: test
}


URL 重写

public function _initRoute(Yaf_Dispatcher $dispatcher)
{
    $router = $dispatcher->getRouter();
    
    // http://yaf/login
    $router->addRoute('login', new Yaf_Route_Rewrite(
        '/login$',
        array(
            'module'         => 'Index', // 默认的模块可以省略
            'controller'    => 'Public',
            'action'        => 'login'
        )
    ));
    
    // http://yaf/logout
    $router->addRoute('logout', new Yaf_Route_Rewrite(
        '/logout$',
        array(
            'controller'    => 'Public',
            'action'        => 'logout'
        )
    ));
    
    // http://yaf/404
    $router->addRoute('404', new Yaf_Route_Rewrite(
        '/404$',
        array(
            'controller'    => 'Public',
            'action'        => 'unknow'
        )
    ));
}

yaf_eloquent's People

Watchers

flyten avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.