多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
目录 [TOC] WorkerA 的模型并不是 ORM 模型,它只是为了方便操作而对查询构造器 WorkerF\DB\DB 的一个封装。 ## 新建模型 你可以在 app/Models 目录或其子目录中新建模型,一个模型的代码实例如下所示: ```php namespace App\Models; use App\Models\Model; // 所有模型都继承自基类 App\Models\Model class Test extends Model { // 指定数据库连接 protected $connection; // 指定数据表 protected $table; // 自定义方法 public function getData() { // 使用查询构造器的方法 return $this->get(); } } ``` ## 使用模型 模型可以调用所有的查询构造器方法,下面是一个在控制器中使用模型的例子: ```php namespace App\Controller; use App\Controller\Controller; use WorkerF\Http\Requests; use App\Models\Test; class TestController extends Controller { // 注入 Test 模型 public function test(Test $test, Requests $request) { $name = $request->name; // 查询获取结果 return $test->where('name', $name)->get(); } } ```