think-orm
webman/think-orm مكوّن قاعدة بيانات يعتمد على top-think/think-orm، ويدعم مجمع الاتصالات والعمل في بيئات الـ coroutine والـ non-coroutine.
تثبيت think-orm
composer require -W webman/think-orm
يجب إعادة التشغيل (restart) بعد التثبيت (reload لا يُؤثر).
ملف الإعدادات
عدّل ملف الإعدادات config/think-orm.php وفقًا لاحتياجاتك الفعلية.
الوثائق
https://www.kancloud.cn/manual/think-orm
الاستخدام
<?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);
}
}
إنشاء النماذج
نماذج think-orm ترث من support\think\Model، كما هو موضّح أدناه:
<?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';
}
يمكنك أيضًا إنشاء نماذج think-orm باستخدام الأمر التالي:
php webman make:model اسم_الجدول
تلميح
يتطلب هذا الأمر تثبيتwebman/console. ثبّته بـcomposer require webman/console ^1.2.13تنبيه
إذا اكتشف الأمر make:model أن المشروع الرئيسي يستخدمilluminate/database، فسيُنشئ ملفات نماذج مبنية على Illuminate بدلًا من think-orm. في هذه الحالة، أضِف المعاملtpلإجبار إنشاء نموذج think-orm:php webman make:model اسم_الجدول tp(حدّثwebman/consoleإن لم ينجح).