本文整理匯總了PHP中ArticleModel::updateArticle方法的典型用法代碼示例。如果您正苦於以下問題:PHP ArticleModel::updateArticle方法的具體用法?PHP ArticleModel::updateArticle怎麽用?PHP ArticleModel::updateArticle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ArticleModel
的用法示例。
在下文中一共展示了ArticleModel::updateArticle方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: editArticle
public function editArticle()
{
$errors = $this->errors;
//實例化Model
$articleModel = new ArticleModel();
$articleTagModel = new ArticleTagModel();
$articleId = $_GET['articleId'];
//根據articleId 查詢文章內容
$article = $articleModel->getArticleById($articleId);
$article['tagId'] = trim($article['tagId'], ',');
//對tagId進行處理
$article['tagId'] = explode(',', $article['tagId']);
//對tagId進行處理
//echo "<pre>";var_dump($article);echo"</pre>";exit;
if ($_POST) {
$pdata = $_POST;
if (!$pdata['title']) {
$result['code'] = '038';
$result['message'] = $errors['038'];
} elseif (!$pdata['typeId']) {
$result['code'] = '039';
$result['message'] = $errors['039'];
} elseif (!$pdata['content']) {
$result['code'] = '030';
$result['message'] = $errors['030'];
} else {
if (isset($pdata['content'])) {
$start = strpos($pdata['content'], '<img');
$end = strpos($pdata['content'], '/>', $start);
$img = substr($pdata['content'], $start, $end - $start + 2);
$preg = '/src="(.*)"[\\s\\n]*\\/>/';
preg_match($preg, $img, $matche);
$pdata['picture'] = $matche[1];
}
if (isset($pdata['tagId']) && $pdata['tagId']) {
$pdata['tagId'] = array_unique($pdata['tagId']);
//數組去重
$articles = $articleModel->getArticleById($pdata['articleId']);
$articles['tagId'] = trim($articles['tagId'], ',');
//對tagId進行處理
$tagArr1 = explode(',', $articles['tagId']);
//對tagId進行處理
$tagArr2 = $pdata['tagId'];
//要添加的(要加1)
$tagArr3 = array_diff($tagArr2, $tagArr1);
$tagArr4 = array_diff($tagArr1, $tagArr2);
// //要刪除的(要減1)
if (!empty($tagArr3)) {
$tagIds1 = implode(',', $tagArr3);
$articleTagModel->setIncByTagIds($tagIds1);
}
if (!empty($tagArr4)) {
$tagIds2 = implode(',', $tagArr4);
$articleTagModel->cutIncByTagIds($tagIds2);
}
$pdata['tagId'] = ',' . implode(',', $pdata['tagId']) . ',';
}
//echo "<pre>";var_dump($pdata);echo"</pre>";exit;
$pdata['adminId'] = $_SESSION['admin']['adminId'];
$results = $articleModel->updateArticle($pdata['articleId'], $pdata);
if ($results) {
$result['code'] = '0';
$result['message'] = $errors['0'];
} else {
$result['code'] = '035';
$result['message'] = $errors['035'];
}
}
echo json_encode($result);
exit;
}
//博主所有文章類型
$allTypes = $this->getAllTypes($_SESSION['admin']['adminId']);
//所有標簽
$allTags = $this->getAllTags($_SESSION['admin']['adminId']);
$this->assign('allTypes', $allTypes);
$this->assign('allTags', $allTags);
$this->assign('article', $article);
$this->assign("pageTitle", "編輯文章");
$this->display();
}