ThinkPHP 控制器内定义全局常量

namespace app\index\controller;
use think\Controller;
define('yzl',3.1415);
class IndexController extends Controller
{
    protected $pi = 3.14;
    protected $pai;
    function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->pai = '3.1415926';
    }

    function index(){
        //$this->assign('pi',$this->pi);
        //$this->assign('pai',$this->pai);
        //$this->assign('yzl',yzl);
        $this->assign([
            'pi'  => $this->pi,
            'pai' => $this->pai,
            'yzl' => yzl
            //'yzl' => test::str
            //'yzl' => test::$str2
        ]);
        return $this->fetch('index');
    }
}

class test
{
    const str = 'aaa';
    static $str2 = 'bbb';
}

{$pi}
{$pai}
{$yzl}

 

你可能感兴趣的:(web)