delete() 공개 메소드

删除当前的记录
public delete ( ) : integer
리턴 integer
 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('删除成功');
     }
 }
 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'));
 }
예제 #3
0
 /**
  * @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;
     }
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
파일: modelTest.php 프로젝트: cnzin/think
    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);
    }
 public function delete($id)
 {
     $model = new Model('Article');
     if ($model->delete($id) !== false) {
         $this->success('删除成功');
     } else {
         $this->error('删除失败');
     }
 }