在yii框架中使用jquery,实现单删批删
来源:互联网 发布:java 表单提交 编辑:程序博客网 时间:2024/06/10 16:26
1:views层
<?phpuse yii\helpers\Url;use yii\helpers\Html;use yii\widgets\LinkPager;use yii\widgets\ActiveForm;$this->registerJsFile("jquery.js",['position' => \yii\web\View::POS_HEAD]);?><table class="table"> <tr> <td><input type="checkbox" id="checkAll"/></td> <td>id</td> <td>商品名称</td> <td>操作</td> </tr> <?php foreach($data as $k=>$v):?> <tr> <td> <input type="checkbox" name="checkid" value=<?=$v['gid']?> > </td> <td><?=$v['gid']?></td> <td><?=$v['gname']?></td> <td><a href="#" class="del" ids=<?=$v['gid']?> >删除</a></td> </tr> <?php endforeach; ?></table><a href="#" id="delAll">批量删除</a><script src="../../web/jquery.js"></script><script> $(function(){ $(document).on('click','#checkAll',function(){ //alert('1'); $(":checkbox[name='checkid']").attr('checked',true); }) $(document).on('click','#delAll',function(){ var vals=""; $(":checkbox[name='checkid']").each(function(){ if($(this).prop("checked")==true){ vals += $(this).val()+","; } }); alert(vals); var url="?r=weibo/show"; $.post(url,{ids:vals}) }) $(document).on('click',".del",function(){ var ids=$(this).attr('ids'); var url="?r=weibo/show"; $.post(url,{ids:ids}); $(this).parent().parent().remove(); }) })</script>
2:controller
<?phpnamespace frontend\controllers;use Yii;use yii\base\InvalidParamException;use yii\db\Query;use yii\web\BadRequestHttpException;use yii\web\Controller;use yii\filters\VerbFilter;use yii\filters\AccessControl;use common\models\LoginForm;use frontend\models\PasswordResetRequestForm;use frontend\models\ResetPasswordForm;use frontend\models\SignupForm;use frontend\models\ContactForm;/** * Site controller */class WeiboController extends Controller{ public function actionShow(){ $query=new Query(); $data=$query->from('goods')->all(); $request=Yii::$app->request; if($request->isPost){ $ids=$request->post("ids"); $ids=trim($ids,","); Yii::$app->db->createCommand()->delete("goods","gid in ($ids)")->execute(); //echo $ids;die;// if($res){// return $this->render('show',['data'=>$data]);// } }else{ return $this->render('show',['data'=>$data]); } }}
0 0
- 在yii框架中使用jquery,实现单删批删
- 在zend studio中使用yii框架
- 在Yii框架中使用PHPExcel
- yii框架中jquery实现删除后重定向页面
- 在Yii框架中使用PHPExcel扩展从数据库导出excel文件功能的实现
- 在Yii框架中如何使用PathInfo形式的URL
- Yii中使用jquery.cookie.js实现的菜单
- 在yii中使用Filter实现RBAC权限自动判断
- 在yii中使用dropDownlist与listData实现下拉菜单
- 在yii中使用memcache
- 在yii中使用memcache
- 在yii中使用分页
- 在yii框架下使用redis数据库
- YII+DWZ框架,使用swfupload实现上传
- 使用yii框架实现邮件发送
- PHP Yii框架中使用smarty模板
- Yii框架中使用ChromePhp调试
- Yii框架中ActiveRecord使用Relations
- linux内存管理数据结构
- 18、Spring MVC 之 HTTP caching support
- array_merge 和 + 在和并数组时候的 相同和不同
- POJ 2253Frogger(最短路floyd)
- 手写数字识别(二)----SVM 实现Mnist-image 手写数字图像识别
- 在yii框架中使用jquery,实现单删批删
- Zookeeper安装
- The Application of Two-level Attention Models in CNN for Fine-grained Image Classification
- Linux 怎样实现非阻塞connect
- 【笔记】树莓派ngrok客户端使用
- centos当更改了/etc/profile后 vi、ls等命令不可用时的解决办法
- 阿里云云服务器硬盘分区及挂载
- Study various way to generate mesh from points
- linux 下ssh用法