<?php

namespace app\admin\controller;

use app\admin\AdminBaseController;
use app\common\model\SinglePageModel;

class Page extends AdminBaseController
{
    public function index()
    {
        $data = SinglePageModel::getConfigValue(SinglePageModel::CODE);
        return view('', [
            'data'  => $data,
            'title' => SinglePageModel::CODE_TITLE,
        ]);
    }

    public function edit()
    {
        $data = $this->_post(SinglePageModel::CODE);
        SinglePageModel::setConfigValue($data);
        ajax_return();
    }

    /**
     * 获取数据
     * @param array $param 要获取的数据
     * @return array
     */
    public function _post(array $param)
    {
        $res = [];
        foreach ($param as $v) {
            if (!empty(input($v))) {
                $res[$v] = input($v);
            }
        }

        return $res;
    }
}