当前位置: 首页>>代码示例>>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;未经允许,请勿转载。