tp5关联
<?php
namespace app\index\model;
use think\Model;
class Admin extends Model{
public function admininfo(){
//一对一的关系
return $this->hasOne('Admininfo','aid','id');
}
//一对多的关系
public function adminimg(){
return $this->hasMany('Adminimg','aid','id');
}
//多对多的关系
public function admintag(){
return $this->belongsToMany('Admintag','Admintagz','tid','aid');
}
}
/**一对一模型使用 */
public function mone(){
// $admin=Admin::get(1);
$list=new Admin();
$admin=$list->get(1);
var_dump($admin->admininfo->info);
}
/**一对多 */
public function mmone(){
$list=new Admin();
$admin=$list->get(1);
$ll= $admin->adminimg;
foreach($ll as $val){
echo $val->img;
}
}
/**多对多 */
public function mbmone(){
$list=new Admin();
$admin=$list->get(1);
$ll=$admin->admintag;
foreach($ll as $val){
echo $val->tag;
}
}