public function editAction() { $p = $_REQUEST; $pId = empty($p['id']) ? die('ID不能为空') : intval($p['id']); $tMO = new CategoryModel(); $tCateRow = $tMO->field('*')->where('id = ' . $pId)->fRow(); if ($_SERVER['REQUEST_METHOD'] == "POST") { $pTitle = empty($p['title']) ? Tool_Fnc::ajaxMsg('分类标题不能为空') : Tool_Fnc::safe_string($p['title']); $pName = empty($p['name']) ? Tool_Fnc::ajaxMsg('分类别名不能为空') : Tool_Fnc::safe_string($p['name']); $pPid = empty($p['pid']) ? 0 : intval($p['pid']); $pKeywords = empty($p['keywords']) ? '' : Tool_Fnc::safe_string($p['keywords']); $pDescription = empty($p['description']) ? '' : Tool_Fnc::safe_string($p['description']); $tTime = time(); if (!count($tCateRow)) { Tool_Fnc::ajaxMsg('分类不存在'); } $tRow = $tMO->field('count(0) c')->where('name = \'' . $pName . '\' and id <> ' . $pId)->fRow(); if (!empty($tRow['c'])) { Tool_Fnc::ajaxMsg('分类别名不能和其他分类重名'); } $tData = array('title' => $pTitle, 'name' => $pName, 'pid' => $pPid, 'keywords' => $pKeywords, 'description' => $pDescription, 'updated' => $tTime, 'id' => $pId); if (!$tMO->update($tData)) { Tool_Fnc::ajaxMsg('修改失败'); } Tool_Fnc::ajaxMsg('修改成功', 1); } $tDatas = $tMO->field('id,pid,name,title')->fList(); $this->assign('tCatelist', Tool_Fnc::getSortedCategory($tDatas)); $this->assign('tId', $pId); $this->assign('tCateRow', $tCateRow); }
public function editAction() { $p = $_REQUEST; $pId = empty($p['id']) ? 0 : intval($p['id']); $tAMO = new ArticleModel(); $tCateMO = new CategoryModel(); if ($_SERVER['REQUEST_METHOD'] == "POST") { $pTitle = empty($p['title']) ? Tool_Fnc::ajaxMsg('文章标题不能为空') : Tool_Fnc::safe_string($p['title']); $pCateid = empty($p['cate_id']) ? 0 : intval($p['cate_id']); $pContent = empty($p['content']) ? Tool_Fnc::ajaxMsg('内容不能为空') : Tool_Fnc::safe_string($p['content']); $pHeadimg = empty($p['head_img']) ? '' : Tool_Fnc::safe_string($p['head_img']); $pDescription = empty($p['description']) ? '' : Tool_Fnc::safe_string($p['description']); $pSource = empty($p['source']) ? '' : Tool_Fnc::safe_string($p['source']); $pInitview = empty($p['initview']) ? '0' : intval($p['initview']); $pStatus = empty($p['status']) ? '0' : intval($p['status']); $pPushtime = empty($p['push_time']) ? Tool_Fnc::ajaxMsg('请选择日期') : Tool_Fnc::safe_string($p['push_time']); $pPushtime = time($pPushtime); $tTime = time(); $tCateRow = $tCateMO->field('*')->where('id = ' . $pCateid)->fRow(); if (empty($tCateRow['id'])) { Tool_Fnc::ajaxMsg('请选择文章分类'); } $tHeadimg = ''; if (!empty($_FILES['img'])) { $tImgurl = '/articleimg/' . date('Y') . '/' . date('m') . '/'; $tDir = APPLICATION_PATH . '/public' . $tImgurl; $tUpload = new Tool_Upload($_FILES['img'], $tDir); $tSavename = $tUpload->getSaveName(); $tExt = $tUpload->extension; $tFile = $tSavename . '.' . $tExt; $tRes = $tUpload->upload($tSavename); if ($tRes == 1) { $tHeadimg = Yaf_Registry::get("config")->web->url->staticimg . $tImgurl . $tFile; if (!empty($pHeadimg)) { unlink(APPLICATION_PATH . '/public' . $pHeadimg); } } } $tHeadimg = empty($tHeadimg) ? $pHeadimg : $tHeadimg; $tData = array('head_img' => $tHeadimg, 'title' => $pTitle, 'content' => $pContent, 'description' => $pDescription, 'cate_id' => $pCateid, 'cate_name' => $tCateRow['name'], 'cate_title' => $tCateRow['title'], 'source' => $pSource, 'initview' => $pInitview, 'updated' => $tTime, 'status' => $pStatus, 'push_time' => $pPushtime, 'id' => $pId); if (!$tAMO->update($tData)) { Tool_Fnc::ajaxMsg('修改失败'); } Tool_Fnc::ajaxMsg('修改成功', 1); } $tDatas = $tCateMO->field('id,pid,name,title')->fList(); $this->assign('tCatelist', Tool_Fnc::getSortedCategory($tDatas)); $tAinfo = $tAMO->field('*')->where('id = ' . $pId)->fRow(); $this->assign('tAinfo', $tAinfo); $this->assign('tId', $pId); }