本文整理汇总了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();
}