1. Go to this page and download the library: Download alex-lee/php-model library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use model\Model;
class Item extends Model
{
// 可选:显式指定表名与主键;不指定则按类名推导(去掉 Model 后缀并转小写)
public $table = 'item';
public $pk = 'id';
// 一对一:Item.id = Item2.id
public function item2()
{
return $this->hasOne(Item2::class, 'id', 'id');
}
// 一对多:Page.type 指向 Item.id,定义时还可继续追加查询条件
public function page()
{
return $this->hasMany(Page::class, 'type', 'id')
->where('page_id', '<=', 100);
}
}