审查视图

application/index/controller/Ajax.php 1.0 KB
Karson authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Lang;

/**
 * Ajax异步请求接口
 * @internal
 */
class Ajax extends Frontend
{
Karson authored
15
    protected $noNeedLogin = ['lang', 'upload'];
Karson authored
16 17 18 19 20 21 22 23 24
    protected $noNeedRight = ['*'];
    protected $layout = '';

    /**
     * 加载语言包
     */
    public function lang()
    {
        header('Content-Type: application/javascript');
25 26 27 28 29 30
        header("Cache-Control: public");
        header("Pragma: cache");

        $offset = 30 * 60 * 60 * 24; // 缓存一个月
        header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
Karson authored
31 32 33
        $controllername = input("controllername");
        $this->loadlang($controllername);
        //强制输出JSON Object
34
        $result = jsonp(Lang::get(), 200, [], ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
Karson authored
35 36
        return $result;
    }
37
Karson authored
38 39 40 41 42
    /**
     * 上传文件
     */
    public function upload()
    {
43
        return action('api/common/upload');
Karson authored
44 45 46
    }

}