當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ActiveRecord::delete方法代碼示例

本文整理匯總了PHP中yii\db\ActiveRecord::delete方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveRecord::delete方法的具體用法?PHP ActiveRecord::delete怎麽用?PHP ActiveRecord::delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\db\ActiveRecord的用法示例。


在下文中一共展示了ActiveRecord::delete方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: delete

 public function delete()
 {
     foreach ($this->answerVariants as $model) {
         $model->delete();
     }
     parent::delete();
 }
開發者ID:igribov,項目名稱:question-list,代碼行數:7,代碼來源:Question.php

示例2: delete

 public function delete()
 {
     foreach ($this->getFotos()->all() as $foto) {
         $foto->delete();
     }
     return parent::delete();
 }
開發者ID:blackvalmiki,項目名稱:billboard-reservation,代碼行數:7,代碼來源:Cartellone.php

示例3: delete

 public function delete()
 {
     if (parent::delete()) {
         Page::updateAll(['category_key' => null], ['category_key' => $this->key, 'lang_code' => $this->lang_code]);
         return true;
     }
     return false;
 }
開發者ID:jarrus90,項目名稱:yii2-content,代碼行數:8,代碼來源:Category.php

示例4: delete

 public function delete()
 {
     foreach ($this->tasks as $task) {
         $task->delete();
     }
     return parent::delete();
     // TODO: Change the autogenerated stub
 }
開發者ID:andy1341,項目名稱:taskmanager,代碼行數:8,代碼來源:Todolist.php

示例5: delete

 /**
  * function ->delete ()
  */
 public function delete()
 {
     //        $now = strtotime('now');
     //        $username = Yii::$app->user->identity->username;
     if (parent::delete()) {
         return true;
     }
     return false;
 }
開發者ID:quyettvq,項目名稱:luspel,代碼行數:12,代碼來源:PurchaseOrderDetail.php

示例6: delete

 public function delete()
 {
     $result = parent::delete();
     if ($result) {
         // При изменении препаратов, менять пользователя и дату изменения в карте глаукомного пациента
         Glaukuchet::findOne($this->id_glaukuchet)->UpdateChangeAttributes();
     }
     return $result;
 }
開發者ID:vovancho,項目名稱:yii2test,代碼行數:9,代碼來源:Glprep.php

示例7: performModelDelete

 /**
  * @param ActiveRecord $model
  * @param array $params
  * @return bool
  * @throws \Exception
  */
 public function performModelDelete(ActiveRecord $model, array $params)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if ($model->delete()) {
         if (isset($params['afterDelete']) && is_callable($params['afterDelete'])) {
             call_user_func($params['afterDelete'], $model);
         }
         $data = ['success' => true, 'message' => Yii::t('management', 'Model has been removed')];
         if (isset($params['success']) && is_callable($params['success'])) {
             $data = array_merge($data, call_user_func($params['success'], $model));
         }
     } else {
         $data = ['success' => false, 'message' => Yii::t('management', 'Model not saved'), 'messages' => ActiveForm::validate($model)];
         if (isset($params['error']) && is_callable($params['error'])) {
             $data = array_merge($data, call_user_func($params['error'], $model));
         }
     }
     return $this->sendJson($data);
 }
開發者ID:hauntd,項目名稱:help-center,代碼行數:25,代碼來源:ManagementController.php

示例8: deleteModelAndRedirect

 /**
  * Suppression d'un objet
  * Cette méthode renvoie un objet de type Response. Elle doit être appelée sur un return comme la méthode redirect() de la classe
  * Controller. Ex. : return $this->redirectAfterCreateSuccess($model)
  *
  * @param ActiveRecord $model
  * @param string|null  $redirectTo
  * @return \yii\web\Response
  */
 protected function deleteModelAndRedirect(ActiveRecord $model, $redirectTo = null)
 {
     try {
         if (!$model->delete()) {
             Yii::$app->session->setFlash('flash-danger', HLib::t('messages', 'Delete unsuccessful'));
         } else {
             Yii::$app->session->setFlash('flash-success', HLib::t('messages', 'Delete successful'));
         }
     } catch (StaleObjectException $s) {
         Yii::$app->session->setFlash('flash-warning', HLib::t('messages', 'This object is outdated. Deletion failed'));
     } catch (IntegrityException $s) {
         Yii::$app->session->setFlash('flash-warning', HLib::t('messages', 'This object is referenced by another object. Deletion failed'));
     } catch (Exception $s) {
         Yii::$app->session->setFlash('flash-danger', HLib::t('messages', 'An error occured during the process. Deletion failed'));
     }
     if (is_null($redirectTo)) {
         $redirectTo = Url::to([$this->getControllerRoute() . '/index']);
     }
     return $this->redirect($redirectTo);
 }
開發者ID:ChristopheBrun,項目名稱:hLib,代碼行數:29,代碼來源:BaseController.php

示例9: unlink

 /**
  * Destroys the relationship between two models.
  *
  * The model with the foreign key of the relationship will be deleted if `$delete` is true.
  * Otherwise, the foreign key will be set null and the model will be saved without validation.
  *
  * @param string $name the case sensitive name of the relationship.
  * @param ActiveRecord $model the model to be unlinked from the current one.
  * @param boolean $delete whether to delete the model that contains the foreign key.
  * If false, the model's foreign key will be set null and saved.
  * If true, the model containing the foreign key will be deleted.
  * @throws InvalidCallException if the models cannot be unlinked
  */
 public function unlink($name, $model, $delete = false)
 {
     $relation = $this->getRelation($name);
     if ($relation->via !== null) {
         if (is_array($relation->via)) {
             /** @var ActiveRelation $viaRelation */
             list($viaName, $viaRelation) = $relation->via;
             $viaClass = $viaRelation->modelClass;
             unset($this->_related[$viaName]);
         } else {
             $viaRelation = $relation->via;
             $viaTable = reset($relation->via->from);
         }
         $columns = [];
         foreach ($viaRelation->link as $a => $b) {
             $columns[$a] = $this->{$b};
         }
         foreach ($relation->link as $a => $b) {
             $columns[$b] = $model->{$a};
         }
         if (is_array($relation->via)) {
             /** @var $viaClass ActiveRecord */
             if ($delete) {
                 $viaClass::deleteAll($columns);
             } else {
                 $nulls = [];
                 foreach (array_keys($columns) as $a) {
                     $nulls[$a] = null;
                 }
                 $viaClass::updateAll($nulls, $columns);
             }
         } else {
             /** @var $viaTable string */
             $command = static::getDb()->createCommand();
             if ($delete) {
                 $command->delete($viaTable, $columns)->execute();
             } else {
                 $nulls = [];
                 foreach (array_keys($columns) as $a) {
                     $nulls[$a] = null;
                 }
                 $command->update($viaTable, $nulls, $columns)->execute();
             }
         }
     } else {
         $p1 = $model->isPrimaryKey(array_keys($relation->link));
         $p2 = $this->isPrimaryKey(array_values($relation->link));
         if ($p1 && $p2 || $p2) {
             foreach ($relation->link as $a => $b) {
                 $model->{$a} = null;
             }
             $delete ? $model->delete() : $model->save(false);
         } elseif ($p1) {
             foreach ($relation->link as $b) {
                 $this->{$b} = null;
             }
             $delete ? $this->delete() : $this->save(false);
         } else {
             throw new InvalidCallException('Unable to unlink models: the link does not involve any primary key.');
         }
     }
     if (!$relation->multiple) {
         unset($this->_related[$name]);
     } elseif (isset($this->_related[$name])) {
         /** @var ActiveRecord $b */
         foreach ($this->_related[$name] as $a => $b) {
             if ($model->getPrimaryKey() == $b->getPrimaryKey()) {
                 unset($this->_related[$name][$a]);
             }
         }
     }
 }
開發者ID:davidpersson,項目名稱:FrameworkBenchmarks,代碼行數:85,代碼來源:BaseActiveRecord.php

示例10: delete

 public function delete()
 {
     if ($this->canDelete()) {
         return parent::delete();
     }
     return false;
 }
開發者ID:joorloohuis,項目名稱:bat-web-frontend,代碼行數:7,代碼來源:Firmware.php

示例11: delete

 /**
  * function ->delete ()
  */
 public function delete()
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = $this;
     if ($log = new UserLog()) {
         $log->username = $username;
         $log->action = "Delete";
         $log->object_class = "ProductTranslation";
         $log->object_pk = $model->id;
         $log->created_at = $now;
         $log->is_success = 0;
         $log->save();
     }
     if (parent::delete()) {
         if ($log) {
             $log->is_success = 1;
             $log->save();
         }
         FileUtils::removeFolder(Yii::$app->params['images_folder'] . $model->image_path);
         return true;
     }
     return false;
 }
開發者ID:quyettvq,項目名稱:luspel,代碼行數:27,代碼來源:ProductTranslation.php

示例12: delete

 public function delete()
 {
     $this->removeImages();
     parent::delete();
 }
開發者ID:AndreyLM,項目名稱:authirities,代碼行數:5,代碼來源:Gallery.php

示例13: delete

 public function delete()
 {
     if (is_file($this->getSrcPath())) {
         unlink($this->getSrcPath());
     }
     if (is_file($this->getPreviewPath())) {
         unlink($this->getPreviewPath());
     }
     parent::delete();
 }
開發者ID:apurey,項目名稱:cmf,代碼行數:10,代碼來源:Magic.php

示例14: delete

 public function delete()
 {
     //$this->gallery->dec();
     $this->unlink_images($this->type);
     return parent::delete();
 }
開發者ID:Kulkow,項目名稱:mainsite,代碼行數:6,代碼來源:Image.php

示例15: delete

 public function delete()
 {
     if ($res = parent::delete()) {
         foreach ($this->tagRelation as $tag) {
             $tag->delete();
         }
         $this->storage->delete($this->image);
         return $res;
     }
     return false;
 }
開發者ID:jarrus90,項目名稱:yii2-blog,代碼行數:11,代碼來源:Post.php


注:本文中的yii\db\ActiveRecord::delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。