1. Go to this page and download the library: Download watsonhaw/think-orm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
watsonhaw / think-orm example snippets
class Order extends Model
{
// Before:直接赋值,随本次 insert 一起写入
public static function onBeforeInsert($model)
{
$model->order_no = date('YmdHis') . mt_rand(1000, 9999);
$model->status = 0;
}
// After:如需持久化需显式 save()
public static function onAfterInsert($model)
{
$model->extra = 'some value';
$model->save(); // 触发 UPDATE
}
}
namespace app\model;
use think\Model;
use think\model\concern\OptimLock;
class User extends Model
{
use OptimLock;
// 可选:自定义锁字段名,默认是 lock_version
// protected $optimLock = 'version';
protected $table = 'user';
protected $pk = 'id';
}