public static function about_action() { // 拦截 self::role('member'); $setting = setting_model::get_by_id(setting_model::id_about); if (visitor::is_post()) { // 拦截 self::csrf('member'); try { // 校验 $checker = new lazy_checker(p()); $checker->check('content', array('change_to' => 'string', 'cannot_be' => array('', '关于不能为空'))); // 执行 $setting->value = $checker->content; $setting->save(); // 成功 self::json_result(true, '关于信息编辑成功。', 0, url('site/about')); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } } else { // 呈现 self::set('content', $setting->value); self::show_page(); } }
public static function edit_action() { // 拦截 self::role('member'); $post = post_model::get_by_id(g_int('id')); self::forward_404_if($post === null, '文章不存在'); if (visitor::is_post()) { // 拦截 self::csrf('member'); try { // 校验 $checker = new lazy_checker(p()); $checker->check_model_rules('post'); // 执行 $props = $checker->get_all(); $tags = $props['tags']; unset($props['tags']); $category_id = $props['category_id']; $post->add_props($props); publish_service::update($post, $category_id, $tags); // 成功 self::json_result(true, '文章编辑成功。', 0, url('post/show?id=' . $post->id)); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } } else { // 呈现 $post->tags = publish_service::fetch_tags_from_post($post); self::set('post', $post); self::set('categories', category_model::get_all()); self::show_page('', 'two'); } }
public static function edit_action() { // 拦截 self::role('member'); $member = member_model::get_by_id(g_int('id')); self::forward_404_if($member === null, '用户不存在'); if (visitor::is_post()) { // 拦截 self::csrf('member'); try { // 校验 $checker = new lazy_checker(p()); $checker->check_model_rules('member', 'edit', $member); // 执行 $member->name = $checker->name; $pass = $checker->pass; if ($pass !== '') { $member->set_pass($pass); } $member->save(); visitor::set_role_var('member', 'name', $member->name); // 成功 self::json_result(true, '用户编辑成功。', 0, url('member/index')); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } } else { // 呈现 self::set('member', $member); self::show_page(); } }
public static function edit_action() { // 拦截 self::role('member'); $id = g_int('id'); $link = link_model::get_by_id($id); self::forward_404_if($link === null, '链接不存在'); if (visitor::is_post()) { // 拦截 self::csrf('member'); try { // 校验 $checker = new lazy_checker(p()); $checker->check_model_rules('link'); // 执行 $link->add_props($checker->get_all()); $link->save(); // 成功 self::json_result(true, '链接编辑成功。', 0, url('link/index')); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } } else { // 呈现 self::set('link', $link); self::show_page(); } }
public static function edit_action() { // 拦截 self::role('member'); $comment = comment_model::get_by_id(g_int('id')); self::forward_404_if($comment === null, '评论不存在'); if (visitor::is_post()) { // 拦截 self::csrf('member'); try { // 校验 $checker = new lazy_checker(p()); $checker->check_model_rules('comment'); // 执行 $comment->add_props($checker->get_all()); $comment->save(); // 成功 self::json_result(true, '评论编辑成功。', 0, url('post/show?id=' . $comment->post_id)); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } } else { // 呈现 self::set('comment', $comment); self::show_page('', 'two'); } }
public static function edit_action() { // 拦截 self::role('member'); $category = category_model::get_by_id(g_int('id')); self::forward_404_if($category === null, '分类不存在'); if (visitor::is_post()) { // 拦截 self::csrf('member'); try { // 校验 $checker = new lazy_checker(p()); $checker->check_model_rules('category'); // 执行 $category->name = $checker->name; $category->save(); // 成功 self::json_result(true, '分类编辑成功。', 0, url('category/index')); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } } else { // 呈现 self::set('category', $category); self::show_page(); } }
public static function edit_action() { // 拦截 self::role('member'); $message = message_model::get_by_id(g_int('id')); self::forward_404_if($message === null, '留言不存在'); if (visitor::is_post()) { // 拦截 self::csrf('member'); try { // 校验 $checker = new lazy_checker(p()); $checker->check_model_rules('message'); // 执行 $message->add_props($checker->get_all()); $message->save(); // 成功 self::json_result(true, '留言编辑成功。', 0, url('site/about')); } catch (check_failed $e) { // 失败 self::json_result(false, $e->get_reasons()); } } else { // 呈现 self::set('message', $message); self::show_page('', 'two'); } }