當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。