AdminAboutController.php 1.9 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\model\AboutModel;
use app\portal\model\PortalPostModel;
use cmf\controller\AdminBaseController;

class AdminAboutController extends AdminBaseController
{
    //关于我们

    //编辑页面
    public function edit(){
        $aboutModel = new AboutModel();
        $post = $aboutModel->where('id',1)->find();
        $contentModel = new PortalPostModel();
        $post['detail'] = $contentModel->getPostContentAttr($post['detail']);
        $post['detail_en'] = $contentModel->getPostContentAttr($post['detail_en']);
        $this->assign('post',$post);
        return $this->fetch();
    }

    //编辑提交
    public function editPost(){
        $data = $this->request->param();
        $result = $this->validate($data, 'AdminAbout.edit');
        if ($result !== true) {
            $this->error($result);
        }

        $aboutModel = new AboutModel();
        // 显式指定更新数据操作
        $contentModel = new PortalPostModel();
        $data['detail'] = $contentModel->setPostContentAttr($data['detail']);
        $data['detail_en'] = $contentModel->setPostContentAttr($data['detail_en']);
        $res = $aboutModel->isUpdate(true)->save($data);
        if($res){
            $this->success('保存成功!');
        }else{
            $this->error('失败');
        }
    }
}