关于帖子编辑功能出现如下错误提示,怎么解决?
代码 edit_topic
public function edit_Topic()
{
if(request()->isPost())
{
$postData = input('post.');
$topic = new TopicModel();
$topicId = $postData['topicId'];
$user = session('user');
$list=[
'title' => $postData['title'],
'content' => $postData['body'],
'category_id' => $postData['category_id'],
'created_at' => intval(microtime(true)),
'user_id' => $user->id,
];
$Topic = new TopicModel();
$Topic->save($list,['id' => $topicId]);
// 处理标签
$tags = $postData['tags'];
foreach ($tags as $tag)
{
if(is_numeric($tag))
{
$this->createTopicTag($tag,$topic->id);
continue;
}
$newTag = $this->createTag($tag);
$this->createTopicTag($newTag->id,$topic->id);
}
$this->success('恭喜,帖子编辑成功。');
}else{
// 显示原来的默认信息
$topicId = input('get.topicId');
$user = session('user');
$topic = TopicModel::getTopic($topicId);
$categoryNames = getcategoryNames($topic->category_id);
$tagsValue = TopicTagModel::getTagsFromTagsByTopicId($topicId);
$tags = TagModel::all();
$this->assign([
'topicId' => $topicId,
'user' => $user,
'topic' => $topic,
'category' => config('category'),
'categoryNames' => $categoryNames,
'tagsValue' => $tagsValue,
'tags' => $tags,
]);
echo $this->fetch('edit_Topic');
}
}
private function createTopicTag($tagId,$topicId)
{
$topic_tag = new TopicTagModel();
$topic_tag->topic_id = $topicId;
$topic_tag->tag_id = $tagId;
$topic_tag->save();
}
private function createTag($tagname)
{
$tag = new TagModel();
$tag->name = $tagname;
$tag->save();
return $tag;
}
正在回答 回答被采纳积分+1
你好,get方法建议参考如下:
public function get($name, $default = false) { $value = $this->handler->get($this->getCacheKey($name)); if (is_null($value)) { return $default; } $jsonData = json_decode($value, true); // 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 byron sampson<xiaobo.sun@qq.com> return (null === $jsonData) ? $value : $jsonData; }
如果不能解决建议以作业形式提交,因为从贴出的部分代码老师无法找出原因所在,如果解决您的问题请采纳,祝学习愉快!
- 参与学习 人
- 提交作业 225 份
- 解答问题 3372 个
掌握用PHP开发互联网网站的必备功能,掌握当下主流的Linux系统开发,并熟练使用热门框架ThinkPhp开发电商团购项目,是通向PHP工程师必经之路。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星