ThinkPHP — how the controller allocates variables to the public template


There should be many solutions, and I will provide an idea here

Define a common controller base from which other controllers inherit

Assign variables in the initialize method of the base controller. The syntax of tp6 is as follows:

<?php namespace app\qingadmin\controller;

use app\BaseController;use think\facade\View;class Base extends BaseController
    public function initialize(){


Public template can be used directly