think-orm
webman/think-orm is a database component developed based on top-think/think-orm, supporting connection pools and both coroutine and non-coroutine environments.
Note
This manual is for webman v2. If you are using webman v1, please refer to the v1 version manual
Installing think-orm
composer require -W webman/think-orm
After installation, you need to restart (reload will not work)
Configuration file
Modify the configuration file config/think-orm.php
according to your actual situation.
Documentation URL
https://www.kancloud.cn/manual/think-orm
Usage
<?php
namespace app\controller;
use support\Request;
use support\think\Db;
class FooController
{
public function get(Request $request)
{
$user = Db::table('user')->where('uid', '>', 1)->find();
return json($user);
}
}
Creating a Model
think-orm models inherit from support\think\Model
, similar to the following
<?php
namespace app\model;
use support\think\Model;
class User extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'user';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $pk = 'id';
}
You can also use the following command to create a model based on think-orm
php webman make:model TableName
Tip
This command requireswebman/console
to be installed. The installation command iscomposer require webman/console ^1.2.13
Note
If the make:model command detects that the main project is usingilluminate/database
, it will create a model file based onilluminate/database
instead of think-orm. In this case, you can force the generation of a think-orm model by adding an extra parameter tp, similar tophp webman make:model TableName tp
(if it doesn't work, please upgradewebman/console
)