kaishargaming / core-lib
PHP核心库,用于Kaisargaming应用程序开发
v0.1.1
2019-12-29 20:07 UTC
Requires
- php: ^7.0.0
- pds/skeleton: ^1.0
- ramsey/uuid: ^3.9
This package is auto-updated.
Last update: 2024-09-29 05:28:58 UTC
README
PHP核心库,用于Kaisargaming应用程序开发。
类集合用于在PHP和MySQL堆栈的应用程序开发环境中作为库使用。
安装
使用composer安装此库。
$ composer require https://github.com/kaisargaming/lib-core.git
模型
Model 是实现简单的MySQL抽象层的基类,它为MVC开发提供了基本的CRUD方法。此基类的大部分方法在扩展后将可链式调用,以提供易于阅读的代码流。
Model 基类的扩展示例。
<?php class User extends Model { public function __construct() { // Construct the parent class with the table name // and optionally the name of the primary key field // the primary key is default to 'id' parent::__construct('users', 'uid'); } }
上述简单的类定义将提供与 users 表进行通信所需的功能。
<?php $users = new User(); // Find all users $all_users = $users->find()->fetch(); // Find users with conditions $male_users = $users->find()->where("`sex`='male' AND `age`>27")->fetch(); // Create a new user // use ->update() for update $users->set('name', 'John') ->set('age', 32) ->set('sex', 'male') ->save();
实用工具
实用工具类应包含在实现过程中便于使用的静态方法。
<?php // Get a formatted time with a specific timezone Utils::getTime('Y-m-d H:i:s', 'Asia/Hong_Kong');