关于本站
“最难不过坚持”
本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作
有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339
2712
39
分类目录
最新评论
- https://jueru.net/
-
评 留言
- :weixiao:
-
评 留言
- :shuijiao: :weiqu: :zhenbang: :leng:
-
评 留言
- :yiwen: :yiwen: :yiwen: :yiwen:
-
评 EasySass: could not generate CSS file. See Output panel for details.
- 这个业务逻辑多少都有点奇怪了,阅读浏览次数增值在新闻详情页的控制器方法里setInc,这怎么还写进模型事件里了。如果非要用onAfterRead也可以,把新闻文章的内容单独分出来一个news_content表,然后把它和news做关联,然后给news_content表的onAfterRead事件做增值处理,这样点进新闻页内查询到文章内容时才会触发它。
-
评 TP6模型事件-查询后onAfterRead不好用
文章标签更多
打开边栏(ESC)
关闭边栏(ESC)
点击产品一级分类,同时获取该分类和属于该分类的子分类的产品
application\home\model\Product.php
/**
* 分页
*/
public function pageQuery(){
$catId = (int)input('catId',0);
$where[] = ['dataFlag','=',1];
$where[] = ['isShow','=',1];
if($catId != 0){
//获取子集
$ids = array();
$ids[] = $catId;
$ids = model('product_cat')->getChild($ids,$ids);
$where[] = ['catId','in',$ids];
}
// if($catId != 0)$where[] = ['catId','=',$catId];
// url里面出现2个catId,所以删除参数catId,http://maiqi.cc/home/Product/lists/catId/5.html?catId=5&page=1
$param = request()->param();
ZHTUnset($param,'catId');
$rs = $this->where($where)
->order('productId', 'desc')
->paginate(12,false,['query' => $param]);
return $rs;
}
application\home\model\ProductCat.php
/**
* 迭代获取下级
*/
public function getChild($ids = array(),$pids = array()){
$result = $this->where("dataFlag=1 and parentId in(".implode(',',$pids).")")->select();
if(count($result)>0){
$cids = array();
foreach ($result as $key =>$v){
$cids[] = $v['catId'];
}
$ids = array_merge($ids,$cids);
return $this->getChild($ids,$cids);
}else{
return $ids;
}
}
thinkphp自定义标签,也可以使用getChilde()方法
/**
* 获取指定产品
*/
public function listProduct($type, $catId = 0, $num, $cache = 0)
{
$cacheData = cache('TAG_PRODUCT_' . $type . "_" . $catId . "_" . $num . "_" . $cache);
if ($cacheData) return $cacheData;
//检测是否有数据
$where = [];
$where[] = ['isShow', '=', 1];
$where[] = ['dataFlag', '=', 1];
if($catId != 0){
//获取子集
$ids = array();
$ids[] = $catId;
$ids = model('product_cat')->getChild($ids,$ids);
$where[] = ['catId','in',$ids];
}
// if($catId > 0)$where[] = ['catId', '=', $catId];
if($type != ''){
$order = ''.$type.' desc,dataSort desc,productId desc';
}else{
$order = 'dataSort desc,productId desc';
}
$product = Db::name('product')
->where($where)
->field('productId,productTitle,productImg,productContent,create_time')
->order($order)
->limit($num)
->select();
// dump($product);
cache('TAG_PRODUCT_' . $type . "_" . $catId . "_" . $num . "_" . $cache, $product, $cache);
return $product;
}
赏
相关推荐
产品多级分类组装,查询一次数据库,组成成多级分类
参考地址:thinkphp只查询一次数据库,组装成3级分类,php递归无限极分类速度慢怎么办
代码:
/**
* 列表
*/
public function listQueryAndChildren(){
$rs = cache('GOODS_CAT');
if(!$rs){
$da...
tp5.1模板中,根据不同情况,调用不同网址或图片
需求:
如果后台填写的是http://类似的网址,则直接链接网址;
如果后台填写的是本站的路径,则前面加上/,绝对路径打开
图片类似情况,也是这样处理
代码:
{volist name='list' id='vo'}
{php}
if(false === stripos($vo['cas...
评论加载中...