本文整理汇总了PHP中app\models\Books::deleteAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Books::deleteAll方法的具体用法?PHP Books::deleteAll怎么用?PHP Books::deleteAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Books
的用法示例。
在下文中一共展示了Books::deleteAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionClearDbFiles
public function actionClearDbFiles()
{
//count number of records to clean
if (\Yii::$app->request->get('count') == 'all') {
$counter = 0;
foreach (Books::find()->select(['book_guid', 'filename'])->each() as $r) {
$file = \Yii::$app->mycfg->Encode(\Yii::$app->mycfg->library->directory . '/' . $r->filename);
if (!file_exists($file)) {
$counter++;
}
}
return $counter;
}
//else clean records in stepping/waves
$stepping = \Yii::$app->request->get('stepping', 5);
//records to delete in 1 wave
$data = [];
$counter = 0;
foreach (Books::find()->select(['book_guid', 'filename'])->each() as $r) {
if ($counter >= $stepping) {
break;
}
$file = \Yii::$app->mycfg->Encode(\Yii::$app->mycfg->library->directory . '/' . $r->filename);
if (!file_exists($file)) {
Books::deleteAll(['book_guid' => $r->book_guid]);
$data[] = $r->book_guid;
$counter++;
}
}
//sleep(1);
return json_encode($data, JSON_UNESCAPED_UNICODE);
}
示例2: actionDeleteBook
public function actionDeleteBook()
{
if (Yii::$app->user->isGuest) {
throw new \yii\web\HttpException(404);
}
if ($id = Yii::$app->request->get(Books::FIELD_ID)) {
Books::deleteAll([Books::FIELD_ID => $id]);
Yii::$app->session->setFlash('success', 'Книга успешно удалена.');
}
return $this->redirect('books-list');
}