-create
方法支持从其它方式创建数据对象,例如,从其它的数据对象,或者数组等
-实例化控制器
new \Home\Controller\UserController() 可以简化为A('User')
echo M('Users')->getLastSql();看sql语句
-遍历
public function MemberList()
{
$stu = M('users');
$list=$stu->select();
$this->assign('li',$list);//分配变量
$this->display();
}
<foreach name="li" item="val" >
{$val.username}
</foreach>
-无限分类M部分
class CatetypeModel extends Model
{
public function Catety()
{
//SELECT * FROM `shop_catetype` ORDER BY concat(path,id)
$info = $this->order("concat(path,id)")->select>();
// echo $list->getLastSql();
foreach ($info as $key => $value)
{
$val = $value['path'];
$con= explode(',', $val);
$len = count($con);
$str = str_repeat("|--", $len-2);
$cname = $str.$value['catename'];
$info[$key]['cnames']=$cname;
}
return $info;
}
}
-ztree插件
http://www.ztree.me/v3/api.php
-js
$.get("__URL__/ProductCategoryTrees",{id:$(obj).attr(id)});
console.log(this);
<foreach name="li" item="val" >
<li><a href="javascript:;" onclick="son(this,'{$val.id}')" id="{$val.id}">{$val.cnames}</a></li>
</foreach>
-ajax
$.ajax({
type:'post',
url:'__URL__/ProductCategoryTrees',
data:'id='+id,
});
-关联表
http://www.thinkphp.cn/topic/8562.html
$result = M()->table(array('表1'=>'表1缩写','表2'=>'表2缩写'))->field('表1缩写.字段1,表2缩写.字段2')->where('表2缩写.wb_id=表1缩写.id')->select()
-只查某值
$ulist ->where($udata)->field('id')->select();
-AJAX
$.ajax(
{
type: "GET",
url: "{:U('Product/ProductGoodsdel')}?id="+sid,
// context: document.body,
success: function(data){
console.log(data);
}});
-购物车—+
<div class="input-append">
<input class="span1 " id = 'num' style="max-width:34px" placeholder="1" size="16" type="text" value="1">
<button class="btn min" type="button" onclick='addn(this,-1);' ><i class="icon-minus"></i></button>
<button class="btn addn" type="button" onclick='addn(this,+1);' ><i class="icon-plus"></i></button>
<button class="btn btn-danger" type="button" onclick='del(this);'><i class="icon-remove icon-white"></i></button>
</div>
function del(obj)
{
obj.parentNode.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode.parentNode);
}
function addn(obj,v)
{
$(obj).siblings('input')[0].value=parseInt($(obj).siblings('input')[0].value) + parseInt(v);
var num = $(obj).siblings('input')[0].value;
if (num <= 1 ) {
$(obj).siblings('input')[0].value=parseInt($(obj).siblings('input')[0].value = 1);
}
if(num == 0){
num = 1;
}