{assign var="datetime" value=$file->GetFileCreateTime()} {assign var="namespace" value=$file->GetNamespace()} {assign var="classes" value=$file->GetClasses()} {assign var="uses" value=$file->GetUses()} GetClassName()} {assign var="tableName" value=$classes[index]->GetTable()->GetName()} {assign var="tableNameHump" value=$classes[index]->GetTable()->GetNameForHump()} {assign var="attrs" value=$classes[index]->GetAttrs()} {assign var="extends" value=$classes[index]->GetExtends()} class {$className}{foreach item=e from=$extends key=i}{if $i == 0} extends {/if}{$e}{/foreach}{ public function __construct($config = []) { parent::__construct({$tableNameHump}::class, $config); } /** * @param null $db * @return {$tableNameHump} | null | array */ public function one($db = null) { return parent::one($db); } /** * @param null $db * @return array | {$tableNameHump}[] */ public function all($db = null) { return parent::all($db); } public static function tableName() { return '{literal}{{{/literal}{{$tableName}}{literal}}}{/literal}'; } {section name=index loop=$attrs} {assign var="fieldName" value=$attrs[index]->GetColumn()->GetName()} {assign var="fieldComment" value=$attrs[index]->GetColumn()->GetComment()} {assign var="attrName" value=$attrs[index]->GetName()} /** * ------------ 字段 {{$fieldName}} * ------------ 表字段注释: {{$fieldComment}} * 如果$val不是function,通过传入的值,直接组成['tableName' => $val]给到where方法 * 如果是function,则闭包函数的类型为 function(string $tableName, ActiveQuery $activeQuery) * @param mixed | callable */ public function filterBy{{$attrName}}($val): self { if(is_callable($val)){ $val("{{$fieldName}}", $this); return $this; } $this->andWhere(["{{$fieldName}}" => $val]); return $this; } // --------------------------------------------- {/section} } {/section}