---------------------------TP——-——-——商 城-----------------------------------
$cat = D('Cat');
$cats = $cat->getTree();
$this->assign('cats' , $cats);
---------
数据库的里边 大栏目是 parent_id = 0 的
小栏目是 parent_id= 大栏目的cat_id 的
---------
<div class="subnav">
<foreach name="cats" item="c">
<if condition="$c['parent_id']==0">
<div>
<span class="left">
{$c['cat_name']}
</span>
<span class="right subnav_right">
<img src="__PUBLIC__/Home/images/line.gif" border="0" id="categorie_ico1">
</span>
</div>
<ul>
<foreach name="cats" item="s">
<if condition="$s['parent_id']==$c['cat_id']">
<li>
<a href="{:U('Home/Index/cat' ,array('cat_id'=>$s['cat_id']))}">
//加的链接点进去就是 调用栏目方法
//依据cat_id 去显示该栏目下所有属于这个cat_id栏目下 商品
//----------------------cat_id = I('get.cat_id');
{$s['cat_name']}
</a>
</li>
</if>
</foreach>
</ul>
</if>
</foreach>
-------------------------------------------------------------------------------
查询 首页的精品 热销 新品 。。。
数据库字段 is_XX =1
$goods = D('Goods');
$goods->where('is_best=1')->order('goods_id desc')->limit(0,3);
$this->assign('best' , $goods->select());
$goods->where('is_hot=1')->order('goods_id desc')->limit(0,3);
$this->assign('hot' , $goods->select());
$goods->where('is_new=1')->order('goods_id desc')->limit(0,3);
$this->assign('new' , $goods->select());
---==---
<foreach name="new" item="g">
<li>
<a href="{:U('Home/Index/goods' , array('goods_id'=>$g['goods_id']))}">
//链接告诉去找 index下的goods 方法处理显示 单个的商品信息页
<img src="{$g.thumb_img}" alt="{$g.goods_name}" />
</a>
<p class="pname">
<a href="{:U('Home/Index/goods' , array('goods_id'=>$g['goods_id']))}" title="{$g.goods_name}">
//链接告诉去找 index下的goods 方法处理显示 单个的商品信息页
{$g.goods_name}{$g.goods_brief}
</a>
</p>
<p class="price">
¥{$g.shop_price}元
</p>
</li>
</foreach>
然后再模板中输出ok!
-------------------------------------------------------------------------------
———————————————————————————————————————————————————————————————————————————————
public function cat(){
/* $cat = D('Cat');
$cats = $cat->getTree();
$this->assign('cats' , $cats);
前面是侧边栏 和首页一样
*/
$goods = D('Goods');
$cnt = $goods->where('cat_id='.I('get.cat_id'))->count('*');
$pager = new \Org\Itbool\MyPage($cnt, 9);
$this->assign('pages' , $pager->show());
//此处分页类 连起来写了。$pager->show() 计算出分页代码;
//取哪个栏目下的商品 根据地址栏的栏目id判断
$goods->where('cat_id='.I('get.cat_id'));
$goods->order('goods_id desc')->limit($pager->firstRow,$pager->listRows);
$this->assign('goods' , $goods->select());
$this->display('category');
}
———————————————————————————————————————————————————————————————————————————————
面包屑导航
public function getMbx($cat_id) {
$row = $this->find($cat_id); # 假设查3号栏,parent_id=>2
$tree[] = $row;
while($row['parent_id'] > 0) { # row['parent_id']=2 , >0
$row = $this->find($row['parent_id']); #查2号栏
$tree[] = $row;
}
return array_reverse($tree);
}
———————————————————————————————————————————————————————————————————————————————
_______________________________________________________________________________
public funtion getMbx($cat_id){
$this->row = $this->find(cat_id);
$tree[] = $row;
while( $row['parent_id'] ){
$row =$this-> find($this->$row['parent_id']);
$tree = $row;
}
return array_reverse($tree);
}
_______________________________________________________________________________
---