当前位置: 首页>>代码示例>>PHP>>正文


PHP Model::delete方法代码示例

本文整理汇总了PHP中think\Model::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::delete方法的具体用法?PHP Model::delete怎么用?PHP Model::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在think\Model的用法示例。


在下文中一共展示了Model::delete方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: delete

 public function delete($id)
 {
     $model = new Model('Comment');
     $data = $model->find($id);
     if (empty($data)) {
         $this->error('评论不存在');
     }
     if (!$model->delete($id)) {
         $this->error('删除失败');
     } else {
         $this->success('删除成功');
     }
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:13,代码来源:CommentController.class.php

示例2: delete

 public function delete($id)
 {
     $model = new Model('Category');
     $category = $model->find($id);
     if (empty($category)) {
         $this->error('分类不存在');
     }
     if ($category['total'] > 0) {
         $this->error('该分类下有文章,不可删除');
     }
     if (!$model->delete($id)) {
         $this->error('删除失败');
     }
     $this->success('删除成功', U('admin/category/index'));
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:15,代码来源:CategoryController.class.php

示例3: delete

 /**
  * @param $cate
  * @param $id
  * @return bool
  */
 public function delete($id)
 {
     //$this->field()
     $raw = $this->field(['savename', 'savepath'])->find($id);
     //echo $raw['savepath'];
     $picName = $this->config['rootPath'] . $raw['savepath'] . $raw['savename'];
     //原图地址
     $picThunbName = $this->config['rootPath'] . $raw['savepath'] . 'thumb/' . $raw['savename'];
     //缩略图地址
     //echo $picName;
     chmod($picName, 0777);
     chmod($picThunbName, 0777);
     $a = unlink($picThunbName);
     $b = unlink($picName);
     if ($a && $b) {
         return parent::delete($id);
     } else {
         return false;
     }
 }
开发者ID:XQ-quadrant,项目名称:gbCMS,代码行数:25,代码来源:PicgridModel.class.php

示例4: delete

 public function delete($options = array())
 {
     $deleteStatus = false;
     $f = $this->getDbFields();
     if (is_array(C('DELETE_TAGS'))) {
         foreach (C('DELETE_TAGS') as $key => $val) {
             if (in_array($key, $f)) {
                 $deleteStatus = true;
                 break;
             }
         }
     }
     if (empty($this->options["where"])) {
         $this->options['where'] = $this->getDeleteWhere($options);
     }
     if (empty($this->options['where'])) {
         $this->error = "Delete No Where";
         return false;
     }
     $op = $this->options;
     $this->_before_delete($op);
     if ($deleteStatus) {
         return $this->deleteTag($op);
     } else {
         $uploadField = array();
         foreach ($this->getListFields() as $key => $val) {
             //如果类型为上传文件,则删除上传的文件。
             if ($val["type"] == "uploadFile") {
                 $uploadField[] = $key;
             }
         }
         if (!empty($uploadField)) {
             $options = $this->options;
             $dataList = $this->field(implode(",", $uploadField))->where($this->options["where"])->select();
             $this->options = $options;
             if ($dataList) {
                 foreach ($dataList as $dataL) {
                     foreach ($uploadField as $fieldName) {
                         $files = json_decode($dataL[$fieldName], true);
                         foreach ($files as $file) {
                             unlink(C("UPLOAD_BASE_PATH") . dirname($file["url"]) . "/" . $file["name"]);
                             if (!empty($file["thumbnail_url"])) {
                                 unlink(C("UPLOAD_BASE_PATH") . dirname($file["thumbnail_url"]) . "/thumbnail_" . $file["name"]);
                             }
                         }
                     }
                 }
             }
         }
         return parent::delete($options);
     }
 }
开发者ID:ppker,项目名称:minephp,代码行数:52,代码来源:DxExtCommonModel.class.php

示例5: testDelete

    public function testDelete()
    {
        $config = $this->getConfig();
        $order_model = new Model('order', $config);
        $order_model->id = 2;
        $flag = $order_model->delete();
        $this->assertEquals(1, $flag);
        $flag = $order_model->delete('1');
        $this->assertEquals(1, $flag);
        $address_model = new Model('user_address', $config);
        $flag = $address_model->delete(['1', '2']);
        $this->assertEquals(2, $flag);
        $user_model = new Model('user', $config);
        $flag = $user_model->using([''])->where('1=1')->delete();
        $this->assertEquals(2, $flag);
        $ru_model = new Model('role_user', $config);
        $flag = $ru_model->delete(['1', '1']);
        $this->assertEquals(1, $flag);
        $sql = <<<EOF
DROP TABLE IF EXISTS `tp_user`;
DROP TABLE IF EXISTS `tp_order`;
DROP TABLE IF EXISTS `tp_user_address`;
DROP TABLE IF EXISTS `tp_role_user`;
EOF;
        $model = new Model('', $this->getConfig());
        $model->execute($sql);
        $flag = $model->db(0, null);
        $this->assertNull($flag);
    }
开发者ID:cnzin,项目名称:think,代码行数:29,代码来源:modelTest.php

示例6: delete

 public function delete($id)
 {
     $model = new Model('Article');
     if ($model->delete($id) !== false) {
         $this->success('删除成功');
     } else {
         $this->error('删除失败');
     }
 }
开发者ID:xialeistudio,项目名称:thinkphp-inaction,代码行数:9,代码来源:ArticleController.class.php


注:本文中的think\Model::delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。