本文整理汇总了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();
}
示例2: delete
public function delete()
{
foreach ($this->getFotos()->all() as $foto) {
$foto->delete();
}
return parent::delete();
}
示例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;
}
示例4: delete
public function delete()
{
foreach ($this->tasks as $task) {
$task->delete();
}
return parent::delete();
// TODO: Change the autogenerated stub
}
示例5: delete
/**
* function ->delete ()
*/
public function delete()
{
// $now = strtotime('now');
// $username = Yii::$app->user->identity->username;
if (parent::delete()) {
return true;
}
return false;
}
示例6: delete
public function delete()
{
$result = parent::delete();
if ($result) {
// При изменении препаратов, менять пользователя и дату изменения в карте глаукомного пациента
Glaukuchet::findOne($this->id_glaukuchet)->UpdateChangeAttributes();
}
return $result;
}
示例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);
}
示例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);
}
示例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]);
}
}
}
}
示例10: delete
public function delete()
{
if ($this->canDelete()) {
return parent::delete();
}
return false;
}
示例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;
}
示例12: delete
public function delete()
{
$this->removeImages();
parent::delete();
}
示例13: delete
public function delete()
{
if (is_file($this->getSrcPath())) {
unlink($this->getSrcPath());
}
if (is_file($this->getPreviewPath())) {
unlink($this->getPreviewPath());
}
parent::delete();
}
示例14: delete
public function delete()
{
//$this->gallery->dec();
$this->unlink_images($this->type);
return parent::delete();
}
示例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;
}