<?php
namespace app\model;
use support\Model;
class User extends Model
{
// 表后缀
private static $table_suffix = '';
public function getTable(): string
{
return 'user_' . self::$table_suffix;
}
/**
* 设置表后缀
*/
public static function setTableSuffix(int $uid)
{
self::$table_suffix = $uid;
return static::class;
}
}
比如说按用户分表,模型代码如上,调用方式如下:
User::setTableSuffix($uid)::where(['type' => 1])->first();
每次都先调用下setTableSuffix方法,请问这样会不会有问题?
@walkor
逻辑能通就没问题