我新建了一个应用,使用标签库的自定义标签调用内容列表的时候就调不出来 显示空白。
但是以及分类 二级分类都没问题 都可以调出来。
<shop:Categories where="$where" categoryId="174" item="vo"> </shop:Categories> //这里调用分类没问题
这里的分类调用正常
到了调用指定分类下的内容列表的时候就出不来了 页面空白的
<shop:articles limit="8" categoryId="174" item="vo"> </shop:articles>
这里调用分类内容的标签就不起作用了
下面的是ApiService文件
public static function articles($param)
{
$portalPostModel = new ShopPostModel();
$where = [
'post.post_status' => 1,
'post.post_type' => 1,
'post.delete_time' => 0
];
$paramWhere = empty($param['where']) ? '' : $param['where'];
$limit = empty($param['limit']) ? 10 : $param['limit'];
$order = empty($param['order']) ? '' : $param['order'];
$page = isset($param['page']) ? $param['page'] : false;
$relation = empty($param['relation']) ? '' : $param['relation'];
$categoryIds = empty($param['category_ids']) ? '' : $param['category_ids'];
$join = [
//['__USER__ user', 'post.user_id = user.id'],
];
$whereCategoryId = null;
if (!empty($categoryIds)) {
$field = !empty($param['field']) ? $param['field'] : 'post.*,min(category_post.category_id) as category_id';
array_push($join, ['__PORTAL_CATEGORY_POST__ category_post', 'post.id = category_post.post_id']);
if (!is_array($categoryIds)) {
$categoryIds = explode(',', $categoryIds);
}
if (count($categoryIds) == 1) {
$whereCategoryId = function (Query $query) use ($categoryIds) {
$query->where('category_post.category_id', $categoryIds[0]);
};
} else {
$whereCategoryId = function (Query $query) use ($categoryIds) {
$query->where('category_post.category_id', 'in', $categoryIds);
};
}
} else {
$field = !empty($param['field']) ? $param['field'] : 'post.*,min(category_post.category_id) as category_id';
array_push($join, ['__PORTAL_CATEGORY_POST__ category_post', 'post.id = category_post.post_id']);
}
$articles = $portalPostModel->alias('post')->field($field)
->join($join)
->where($where)
->where($paramWhere)
->where($whereCategoryId)
->where('post.published_time', ['> time', 0], ['<', time()], 'and')
->order($order)
->group('post.id');
$return = [];
if (empty($page)) {
$articles = $articles->limit($limit)->select();
if (!empty($relation) && !empty($articles['items'])) {
$articles->load($relation);
}
$return['articles'] = $articles;
} else {
if (is_array($page)) {
if (empty($page['list_rows'])) {
$page['list_rows'] = 10;
}
$articles = $articles->paginate($page);
} else {
$articles = $articles->paginate(intval($page));
}
if (!empty($relation) && !empty($articles['items'])) {
$articles->load($relation);
}
$articles->appends(request()->get());
$articles->appends(request()->post());
$return['articles'] = $articles->items();
$return['page'] = $articles->render();
$return['total'] = $articles->total();
$return['total_pages'] = $articles->lastPage();
}
return $return;
}
下面的是标签库文件
/**
* 定义标签列表
*/
protected $tags = [
// 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次
'articles' => ['attr' => 'field,where,limit,order,page,relation,returnVarName,pageVarName,categoryIds', 'close' => 1],//非必须属性item
'tagarticles' => ['attr' => 'field,where,limit,order,page,relation,returnVarName,pageVarName,tagId', 'close' => 1],//非必须属性item
'breadcrumb' => ['attr' => 'cid', 'close' => 1],//非必须属性self
'categories' => ['attr' => 'ids,where,order', 'close' => 1],//非必须属性item
'category' => ['attr' => 'id', 'close' => 1],//非必须属性item
'subcategories' => ['attr' => 'categoryId', 'close' => 1],//非必须属性item
'allsubcategories' => ['attr' => 'categoryId', 'close' => 1],//非必须属性item
];
/**
* 文章列表标签
*/
public function tagArticles($tag, $content)
{
$item = empty($tag['item']) ? 'vo' : $tag['item'];//循环变量名
$order = empty($tag['order']) ? 'post.published_time DESC' : $tag['order'];
$relation = empty($tag['relation']) ? '' : $tag['relation'];
$pageVarName = empty($tag['pageVarName']) ? '__PAGE_VAR_NAME__' : $tag['pageVarName'];
$returnVarName = empty($tag['returnVarName']) ? 'articles_data' : $tag['returnVarName'];
$field = "''";
if (!empty($tag['field'])) {
if (strpos($tag['field'], '$') === 0) {
$field = $tag['field'];
$this->autoBuildVar($field);
} else {
$field = "'{$tag['field']}'";
}
}
$where = '""';
if (!empty($tag['where']) && strpos($tag['where'], '$') === 0) {
$where = $tag['where'];
}
$limit = "''";
if (!empty($tag['limit'])) {
if (strpos($tag['limit'], '$') === 0) {
$limit = $tag['limit'];
$this->autoBuildVar($limit);
} else {
$limit = "'{$tag['limit']}'";
}
}
$page = "''";
if (!empty($tag['page'])) {
if (strpos($tag['page'], '$') === 0) {
$page = $tag['page'];
$this->autoBuildVar($page);
} else {
$page = intval($tag['page']);
$page = "'{$page}'";
}
}
$categoryIds = "''";
if (!empty($tag['categoryIds'])) {
if (strpos($tag['categoryIds'], '$') === 0) {
$categoryIds = $tag['categoryIds'];
$this->autoBuildVar($categoryIds);
} else {
$categoryIds = "'{$tag['categoryIds']}'";
}
}
if (!empty($tag['order']) && strpos($tag['order'], '$') === 0) {
$order = $tag['order'];
$this->autoBuildVar($order);
} else {
$order = "'{$order}'";
}
$parse = <<<parse
<?php
\${$returnVarName} = \app\shop\service\ApiService::articles([
'field' => {$field},
'where' => {$where},
'limit' => {$limit},
'order' => {$order},
'page' => {$page},
'relation'=> '{$relation}',
'category_ids'=>{$categoryIds}
]);
\${$pageVarName} = isset(\${$returnVarName}['page'])?\${$returnVarName}['page']:'';
?>
<volist name="{$returnVarName}.articles" id="{$item}">
{$content}
</volist>
parse;
return $parse;
}
头部文件中调用标签库
<taglib name="app\portal\taglib\Portal,app\shop\taglib\Shop"/>
麻烦哪位高手帮忙看看。感谢!!
0.话题发布后没及时显示,请联系官方QQ群管理;
1.话题支持代码,qq截屏直接粘贴,和QQ群一样;
2.问题描述清,比如服务器版本,程序版本;
3.能上代码,就不用文字;
4.把问题发到话题后再发QQ群;
5.如果感觉回复者解答的不错,可以发红包!
6.多帮助别人也是对自己的锻炼!
7.付费讨论中只有提问者和付费用户才可以查看回复
1.评论积分+1;每天最多10次奖励
2.发布话题积分+1;每天最多5次奖励
3.垃圾评论积分-500;
4.黄色,暴力,违反我国法律评论直接封号