where("pid=$id")->order("s"/> where("pid=$id")->order("s">

本人念的一个thinkphp无级分类方法,使用字符串传到模板

WBOY
Release: 2016-06-13 11:54:41
Original
907 people have browsed it

本人想的一个thinkphp无级分类方法,使用字符串传到模板

public function _getMenu($id=0,$t=0){<br />		$category = M("category");<br />		$data = $category->where("pid=$id")->order("sort asc")->select();<br />		<br />		if($data){<br />			$t++;	<br />			$data2['leavel'] = $t;<br />			$category->where("pid=$id")->save($data2);			//层级<br />			foreach($data as $key=>$value){	<br />			$sort = $value['sort'];<br />			$id = $value['id'];	<br />			$this->str .= '<tr><td><input name = "ids['.$id.']" type = "text" value = "'.$sort.'"></td>';			<br />			$this->str .= "<td>". $value['id']."</td>";<br />			if($t>1){<br />				if()			<br />			$this->str .= "<td>|-----".$value['name']."</td>";<br />			<br />			}else{<br />			$this->str .= "<td>".$value['name']."</td>";<br />			}<br />				$this->str .= "<td>".$value['group']."</td>";<br />				$id = $value['id'];<br />			$this->str .= '<td><a href = http://localhost/tptest/index.php/Article/deletelanmu?id='.$id.'>删除</a></td></tr>';<br />			$this->_getMenu($value['id'],$t);<br />			}<br />				<br />			}<br />		}
Copy after login

------解决方案--------------------
那你就要判断当前父类下 所有栏目数是否等于本栏目位置(第几条),如果相等,则就是最后一条,就满足你的要求了
------解决方案--------------------
分类数组为 $data 则
end($data);
$ek = key($data); //之后一个分类在 $data 中的键值

循环中加入
if($key == $ek)  $this->str .= "


------解决方案--------------------
____".$value['name']."";
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template