ThinkPHP 商城属性添加
2016-05-15 13:21
561 查看
//获得属性预览 public function createInput($sid,$kjname){ $input = M('shopattr')->find($sid); if($input['stype'] == 1){ //单选 $stext = $input['stext']; $arr = preg_split('/\n/',$stext ); $str = ''; $i=0; foreach($arr as $v){ $v = trim($v); if($i==0){ $str.= "<input type='radio' name='".$kjname."' checked value='$v'>$v"; }else{ $str.= "<input type='radio' name='".$kjname."' value='$v'>$v"; } $i++; } return $str; } if($input['stype'] == 2){ //多选 $stext = $input['stext']; $arr = preg_split('/\n/',$stext ); $str = ''; foreach($arr as $v){ $v = trim($v); $str.= "<input type='checkbox' name=' ".$kjname."[]' value='$v'>$v"; } return $str; } if($input['stype']==3){ //文本框 return '<input type="text" name="'.$kjname.'" />'; }}
//获取数据列表
public function getData(){
$model = D('shopattrView');
$page = I('request.page');
$rows = I('request.rows');
$aid = I('request.aid');
$data = $model->where(array('aid'=>$aid))->limit( $rows*($page-1),$rows )->select();
$rowArr = array();
foreach($data as $v){
$v['view'] = $this->createInput($v['sid'],$v['kjname']);
$rowArr[] = $v;
}
$list = array(
'rows'=>$rowArr,
'total'=>$model->count()
);
echo json_encode($list);
}
相关文章推荐