1.控制器中
$list = Userlawsbook::where($where)->with('lawsbook')->paginate(7); // 此處查出來為數組對象
dump[0]['lawsbook']; // 可直接打印出第一個關聯的對象
2.模型中
public function lawsbook()
{
return $this->belongsTo('app\common\model\china\Lawsbook', 'china_lawsbook_id', 'id', [], 'LEFT')->setEagerlyType(0); // 關聯模型
}
3.模板中輸出
{volist name="list" id="v"}
<li>
<span class="time">{:date('Y-m-d H:i:s',$v['createtime'])}</span>
<p class="henadP">{$v['lawsbook']['title']}</p> <!--關聯中表中的title-->
<a href="#">下載</a>
</li>
{/volist}
