首页 > 资讯列表 > 编程/数据库 >> PHP

php下拉选项的批量操作的示例讲解

PHP 2014-12-23 07:21:40 转载来源: 网络整理/侵权必删

本文为大家讲解的是php下拉选项的批量操作的示例,感兴趣的同学参考下. 实现功能,操作项可以单独删除,批量项可以批量删除,批量显示,隐藏(改广告的数据库的status_is的值); 1

本文为大家讲解的是php下拉选项批量操作示例,感兴趣的同学参考下.

实现功能,操作项可以单独删除,批量项可以批量删除,批量显示,隐藏(改广告的数据库的status_is的值);

1.视图关键点:


<td ><input type="checkbox" name="id[]" value="<?php echo $row->id?>">
        <?php echo $row->id?></td>

<div class="fixsel">
          <input type="checkbox" name="chkall" id="chkall" onclick="checkAll(this.form, 'id')" />
          <label for="chkall">全选</label>
          <select name="command">
            <option>选择操作</option>
            <option value="adDelete">删除</option>
            <option value="adVerify">显示</option>
            <option value="adUnVerify">隐藏</option>
          </select>
          <input id="submit_maskall" class="button confirmSubmit" type="submit" value="提交" name="maskall" />
        </div>

/*单个删除*/

<a href="<?php echo  $this->createUrl('batch',array('command'=>'adDelete', 'id'=>$row->id))?>" class="confirmSubmit">

2.控制器:


/**
     * 批量操作
     *
     */
    public function actionBatch ()
    {
        if (XUtils::method() == 'GET') {     //单个删除是get方式
            $command = trim($_GET['command']);
            $ids = intval($_GET['id']);
        } else
            if (XUtils::method() == 'POST') {
                $command = trim($_POST['command']);
                $ids = $_POST['id'];
                is_array($ids) && $ids = implode(',', $ids);
            } else {
                XUtils::message('errorBack', '只支持POST,GET数据');
            }
        empty($ids) && XUtils::message('error', '未选择记录');

        switch ($command) {

            case 'adDelete':
                parent::_acl('ad_delete');
                parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'删除广告,ID:'.$ids));
                parent::_delete(new Ad(), $ids, array ('ad' ), array ('attach_file' ));
                break;
            case 'adVerify':
                parent::_acl('ad_verify');
                parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'广告状态变更为显示,ID:'.$ids));
                parent::_verify(new Ad(), 'verify', $ids, array ('ad' ));

                break;
            case 'adUnVerify':
                parent::_acl('ad_verify');
                parent::_adminiLogger(array('catalog'=>'delete', 'intro'=>'广告状态变更为隐藏,ID:'.$ids));
                parent::_verify(new Ad(), 'unVerify', $ids, array ('ad' ));
                break;
            default:
                throw new CHttpException(404, '错误的操作类型:' . $command);
                break;
        }

    }

父类的删除函数:


protected function _delete ($model = null, $id = '', $redirect = 'index', $attach = null, $pkField = 'id')
    {
        if ($attach) {          //如果有附件要删除广告的图片
            $data = $model->findAll($pkField . ' IN(:id)', array (':id' => $id ));
            foreach ((array) $data as $row) {
                foreach ((array) $attach as $value) {
                    if (! empty($row[$value])) {
                        @unlink($row[$value]);
                    }
                }
            }
        }
        $result = $model->deleteAll(array ('condition' => 'id IN(' . $id . ')' ));
        //刷新缓存
        self::_refreshCache($model);
        $this->redirect($redirect);
    }

protected function _verify ($model = null, $type = 'verify', $id = '', $redirect = 'index', $cdField = 'status_is', $pkField = 'id')
    {
        $criteria = new CDbCriteria();
        $criteria->condition = $pkField . ' IN(' . $id . ')';
        $showStatus = $type == 'verify' ? 'Y' : 'N';
        $result = $model->updateAll(array ($cdField => $showStatus ), $criteria);
        //刷新缓存
        self::_refreshCache($model);
        $this->redirect($redirect);
    }

标签: php 下拉 选项 批量 操作 示例 讲解


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持