/** * 添加文章的操作 */ public function add() { $PostEvent = new PostsEvent(); $tpl_type_list = $PostEvent->get_tpl_type_list(); $post = $PostEvent->restore_from_cookie(); //投稿员只能看到自己的 if (!$this->noVerify()) { //TODO 使用原生SQL提高效率 $user_id = get_current_user_id(); $user = D('User', 'Logic')->detail($user_id); $role_id = $user["user_role"]["role_id"]; $role = D('Role')->where(array('id' => $role_id))->find(); $where['cat_id'] = array('in', json_decode($role["cataccess"])); $cats = D('Cats', 'Logic')->where($where)->select(); foreach ($cats as $key => $value) { $cats[$key]['cat_slug'] = $cats[$key]['cat_name']; } } else { $cats = D('Cats', 'Logic')->category(); $tags = D('Tags', 'Logic')->select(); } $this->assign('tpl_type', gen_opinion_list($tpl_type_list)); $this->assign("info", $post); $this->assign("tags", $tags); $this->assign("cats", $cats); $this->assign("handle", U('Admin/Posts/addHandle')); $this->assign("publish", "发布"); $this->display(); }