TP5
model 模组
<?php
namespace app\index\model;
use think\Model;
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/1/2
* Time: 22:06
*/
class Banner extends Model
{
public function comments()
{
return $this->hasMany(‘Comment‘,‘memberid‘,‘px‘)->field(‘id,goodsid,memberid,content,add_time‘);
}
}
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/1/2
* Time: 22:11
*/
namespace app\index\model;
use think\Model;
class Comment extends Model
{
}
控制器
<?php
namespace app\index\controller;
use app\index\model\Banner;
class Index
{
public function index()
{
$article =new Banner();
$arr = Banner::with(‘comments‘)->paginate(1);
echo "<pre>";
foreach($arr as $key => $value){
print_r($value->toArray());
}
// return View(‘index‘);
}
}
原文:https://www.cnblogs.com/corvus/p/12142428.html