无限级分类 读取、排序、更新

来源:互联网 发布:中国古代美女 知乎 编辑:程序博客网 时间:2024/06/06 14:27

create table hd_cate(

id int unsigned not null  primary key auto_increment,

name char(15) not null default '',

pid int unsigned not null defualt 0,

sort smallint(6) not null default 100

)




categoryAction.class.php


class caterotyAction extends CommonAction{

public function AddCate(){

$this->display();

}

$cate = M('cate')->order('sort ASC')->select();

//p($cate);//打印

      //  $this->cate = $cate;

$this->assing('cate',$cate)->display();


//添加表单

public function runaddcate(){

if(M('cate')->add($_POST)){

$this->success('添加成功',U(GROUP_NAME . '/category/index'));

}else{

$this->error("失败");

}

}

}


addCate.html

<CSS faile='__PUBLIC__/cSS/PUBLIC.CSS' />//引入CSS

提交到 <form action="{:U(GROUP_NAME . '/category/runAddcate')}"


index.html

//数组循环读取

<foreach name='cate' item='v'>

{$v.id}

</foreach>


更新

public function sortcate(){

$db = M('cate');

$db->where()->setField('sort',)更新一个字段方法,更新字段 更新值


foreach($_POST as $id =>$sort){

$db->where(array('id'=>$id))->setField('sort',$sort);

$this->redirect()  //调转

}

}




0 0
原创粉丝点击