国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

作業(yè):Product模塊添加,修改,刪除操作

Original 2018-11-30 21:32:34 439
abstract:作業(yè):Product模塊添加,修改,刪除操作關(guān)于添加操作,由于有editor中有可能會傳入圖片,因此會有upload上傳操作方法public function upload(){ $file=Request::file('img'); if($info=$file->validate(['ext'=>'jpg,jpeg

作業(yè):Product模塊添加,修改,刪除操作

關(guān)于添加操作,由于有editor中有可能會傳入圖片,因此會有upload上傳操作方法

public function upload(){
		$file=Request::file('img');
		if($info=$file->validate(['ext'=>'jpg,jpeg,png,gif'])->move('upload')){
			return json(['errno'=>0,'data'=>['/upload/'.$info->getSaveName()]]);
		}else{
			return $file->getError();
		}
	}
	
	public function doAdd(){
		//獲取提交過來的數(shù)據(jù)
		$data=Request::param();
		$title=$data['title'];
		$info=ProductModel::where('title',$title)->find();
		if($info==true){
			return ['res'=>0,'msg'=>'產(chǎn)品重復(fù)'];
		}
		$data['time']=time();
		$data['username']=Session::get('username');
		$product=new ProductModel();
		if($product->save($data)){
			return ['res'=>1,'msg'=>'發(fā)布成功'];
		}else{
			return ['res'=>0,'msg'=>'發(fā)布失敗'];
		}

html相關(guān)添加操作

   form.on('submit(add)', function(data){
            console.log(data);
            //發(fā)異步,把數(shù)據(jù)提交給php
            $.post('{:url(\'doAdd\')}',{
            	'title':$('#title').val(),
            	'sort':$('#sort').val(),
            	'desc':$('#desc').val(),
            	'content':editor.txt.html(),
            	'once':$('#once').val(),
            	'over_night':$('#over_night').val(),
            },function(data){
            	if(data.res==1){
	            		layer.alert(data.msg, {icon: 6},function () {
	                // 獲得frame索引
	                var index = parent.layer.getFrameIndex(window.name);
	                //關(guān)閉當(dāng)前frame
	                parent.layer.close(index);
	            });            		
            }else{
            			layer.alert(data.msg, {icon: 6},function () {
	                // 獲得frame索引
	                var index = parent.layer.getFrameIndex(window.name);
	                //關(guān)閉當(dāng)前frame
	                parent.layer.close(index);
	            });            		
            }
         })

            return false;
          });

編輯處理

public function edit(){
		$proId=Request::param('id');
		$product=ProductModel::get($proId);
		$this->assign('product',$product);
		return $this->fetch();
	}
	
	public function doEdit(){
		//獲取前臺提交過來的數(shù)據(jù)
		$data=Request::param();
		$product=new ProductModel();
		$data['time']=time();
		$data['username']=Session::get('username');
		$info=$product->save([
			'title'=>$data['title'],
			'desc'=>$data['desc'],
			'content'=>$data['content'],
			'once'=>$data['once'],
			'over_night'=>$data['over_night'],
			'time'=>$data['time'],
			'username'=>$data['username'],
		],['id'=>$data['id']]);

	if($info){
		return ['res'=>1,'msg'=>'更新成功'];
	}else{
		return ['res'=>0,'msg'=>'更新失敗'];
	}
		}
添加一個hidden id.
 <input type="hidden" id="id" name="id" value="{$product.id}">
  $.post('{:url(\'doEdit\')}', {
                'id': $('#id').val(),
                'title': $('#title').val(),
                'desc': $('#desc').val(),
                'content': editor.txt.html(),
                'once': $('#once').val(),
                'over_night': $('#over_night').val(),
            }, function (data) {
                if (data.res == 1) {
                    layer.alert(data.msg, {icon: 6}, function () {
                        // 獲得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //關(guān)閉當(dāng)前frame
                        parent.layer.close(index);
                    });
                } else {
                    layer.alert(data.msg, {icon: 6}, function () {
                        // 獲得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //關(guān)閉當(dāng)前frame
                        parent.layer.close(index);
                    });
                }
            })

1.PNG

2.PNG


3.PNG

4.PNG

Correcting teacher:韋小寶Correction time:2018-12-01 09:20:58
Teacher's summary:不錯不錯!寫的很棒哦!項目要多寫才能看到成效哦!

Release Notes

Popular Entries