本文整理汇总了PHP中app\models\Post::deleteAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::deleteAll方法的具体用法?PHP Post::deleteAll怎么用?PHP Post::deleteAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Post
的用法示例。
在下文中一共展示了Post::deleteAll方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionDelete
public function actionDelete($id)
{
$model = Post::find()->where(['id' => $id])->one();
$model->unlinkAll('categories', true);
Post::deleteAll(['id' => $id]);
return $this->actionNew();
}
示例2: beforeDelete
public function beforeDelete()
{
if (parent::beforeDelete()) {
Post::deleteAll(['cate_id' => $this->id]);
return true;
} else {
return false;
}
}
示例3: actionIndex
public function actionIndex()
{
if (!$this->confirm('Remove all data and insert demo data?')) {
return false;
}
Category::deleteAll();
$categories = [['id' => 1, 'alias' => 'general', 'title' => 'General'], ['id' => 2, 'alias' => 'general-about', 'title' => 'About this script', 'parentId' => 1], ['id' => 3, 'alias' => 'general-faq', 'title' => 'F.A.Q.', 'parentId' => 1], ['id' => 4, 'alias' => 'cat13', 'title' => 'Category 1.3', 'parentId' => 1], ['id' => 5, 'alias' => 'cat14', 'title' => 'Category 1.4', 'parentId' => 1], ['id' => 6, 'alias' => 'cat15', 'title' => 'Category 1.5', 'parentId' => 1], ['id' => 7, 'alias' => 'cat2', 'title' => 'Category 2'], ['id' => 8, 'alias' => 'cat21', 'title' => 'Category 2.1', 'parentId' => 7], ['id' => 9, 'alias' => 'cat22', 'title' => 'Category 2.2', 'parentId' => 7], ['id' => 10, 'alias' => 'cat23', 'title' => 'Category 2.3', 'parentId' => 7], ['id' => 11, 'alias' => 'cat3', 'title' => 'Category 3'], ['id' => 12, 'alias' => 'cat31', 'title' => 'Category 3.1', 'parentId' => 11], ['id' => 13, 'alias' => 'cat32', 'title' => 'Category 3.2', 'parentId' => 11], ['id' => 14, 'alias' => 'cat33', 'title' => 'Category 3.3', 'parentId' => 11]];
foreach ($categories as $item) {
$model = new Category();
$model->setAttributes($item, false);
$model->save();
}
Post::deleteAll();
$posts = [['title' => 'Post 1 - 1', 'alias' => 'post11', 'categoryId' => 1], ['title' => 'Post 1 - 2', 'alias' => 'post12', 'categoryId' => 1], ['title' => 'Post 1 - 3', 'alias' => 'post13', 'categoryId' => 1], ['title' => 'Post 1 - 4', 'alias' => 'post14', 'categoryId' => 1], ['title' => 'Post 1.1 - 1', 'alias' => 'post111', 'categoryId' => 2], ['title' => 'Post 1.1 - 2', 'alias' => 'post112', 'categoryId' => 2], ['title' => 'Post 1.1 - 3', 'alias' => 'post113', 'categoryId' => 2], ['title' => 'Post 1.1 - 4', 'alias' => 'post113', 'categoryId' => 2], ['title' => 'Post 1.2 - 1', 'alias' => 'post121', 'categoryId' => 3], ['title' => 'Post 1.2 - 2', 'alias' => 'post122', 'categoryId' => 3], ['title' => 'Post 1.2 - 3', 'alias' => 'post123', 'categoryId' => 3], ['title' => 'Post 1.3 - 1', 'alias' => 'post131', 'categoryId' => 4], ['title' => 'Post 1.3 - 2', 'alias' => 'post132', 'categoryId' => 4], ['title' => 'Post 1.3 - 3', 'alias' => 'post133', 'categoryId' => 4]];
foreach ($posts as $item) {
$model = new Post();
$model->setAttributes($item, false);
$model->save(false);
}
$this->printTree(Category::find()->all());
}
示例4: actionDelete
public function actionDelete()
{
$status = array();
$postID = $_POST['postID'];
$postID = (int) $postID;
if ($postID == NULL) {
$status['status'] = "faild";
} else {
$postModel = Post::deleteAll(['postID' => $postID]);
if ($postModel == 1) {
$status["status"] = "ok";
} else {
$status["status"] = "faild";
}
}
echo json_encode($status);
}