<?php
namespace app\controller\en;

use app\controller\BaseController;
use app\model\System;

/**
 * 控制器基础类
 */
class Base extends BaseController
{
    //需要向模板传递的值
    protected $data = [];
    //系统配置信息
    protected $system = [];
    protected $lang = 'en';

    // 初始化
    protected function initialize()
    {
        $this->middleware = ['csrf'];
        $this->system = System::getSystem();
        $this->data['system'] = $this->system;
        $this->data['lang'] = 'en';
//        var_dump($this->request->controller());
//        var_dump($this->request->action());
//        exit;
        $this->setCsrfToken();
    }

    //设置SEO信息
    protected function setSeo($title, $keywords, $description)
    {
        $this->data['seoTitle'] = $title;
        $this->data['seoKeywords'] = $keywords;
        $this->data['seoDescription'] = $description;
    }

    //设置默认SEO信息
    protected function setDefaultSeo()
    {
        $this->data['seoTitle'] = $this->system['seo_title_en'];
        $this->data['seoKeywords'] = $this->system['seo_keywords_en'];
        $this->data['seoDescription'] = $this->system['seo_description_en'];
    }

    //模板
    protected function view($template = '')
    {
        return view($template)->assign($this->data);
    }

    protected function setCsrfToken()
    {
        $this->data['_token'] = session('_token') ?? '';
    }
}
