列表增加调用某个字段
<p>文库读取列表的一个函数</p><pre class="brush:html;toolbar:false">public static function listCategoryRecommendLatest($categoryId, $limit = 6)
{
return Cache::remember('WenkuDocLatest:' . $categoryId . ':' . $limit, 60, function () use ($categoryId, $limit) {
$categoryIds = array_merge([$categoryId], WenkuCategoryUtil::childIds($categoryId));
$records = ModelUtil::model('wenku_doc')
->where(['status' => WenkuDocStatus::VERIFY_PASS, 'isDeleted' => false, 'isRecommend' => true,])
->whereIn('categoryId', $categoryIds)
->limit($limit)
->orderBy('id', 'desc')
->get(['hash', 'title', 'ext', 'cover', 'pagePreviews', 'memberUserId'])->toArray();
ModelUtil::decodeRecordsJson($records, ['pagePreviews']);
foreach ($records as $k => $v) {
$records[$k]['cover'] = WenkuDocUtil::cover($v);
unset($records[$k]['pagePreviews']);
}
MemberUtil::mergeMemberUserBasics($records);
return $records;
});
}</pre>
<p>想读取页数,日期,分类id等字段,在get这里加了字段</p>
<pre class="brush:html;toolbar:false">->get(['hash', 'title', 'ext', 'cover', 'pagePreviews', 'memberUserId', 'created_at', 'categoryId', 'pageCount'])->toArray();</pre>
<p><br></p>
<p>在视图页面调用<br></p>
<pre class="brush:html;toolbar:false"> {{$record['pageCount']}} , {{$record['created_at']}}, {{$record['categoryId']}}</pre>
<p>这样会出错500,应该怎么修改,是不是还要修改哪里<br></p><hr>以下是回复内容:<br><div class="ub-html content">
<p>增加字段按照你这样描述的方法是可行的。</p>
<p>看到该方法是使用了缓存的,请检查下是否是使用了缓存导致的错误。</p>
</div><hr><br>采集网址:<br>https://modstart.com/thread/958
页:
[1]