Laravel-当我在另一个帮助程序类中时,我无法调用get配置助手



消息:
找不到类"帮助程序\配置"

文件:应用程序/类/助手/助手.php

public static function getDictionary(){                    
$timezone = Config::get('app.dictionary');     

文件:配置/应用程序.php。

'aliasis => array(
'Helper'          => 'HelpersHelper'

文件:应用程序/配置/应用程序.php

'dictionary'    =>  array(
'EMAIL'     =>  'crm@xxxx.com',
'VERSION'       => "1.0.0"
)

我错过了任何命名空间或使用行吗?

因为您位于HelpersHelper文件中的命名空间中,所以当您引用该文件中的Config时,PHP 假定您指的是 Helpers 命名空间中的一个类。你需要在它前面加上一个,说你的意思是类Config"根",或者使用use语句:

  1. 直接参考:

    $timezone = Config::get('app.dictionary');
    
  2. use它:

    use Config;
    class Helper
    {
         public static function getDictionary()
        {
            $timezone = Config::get('app.dictionary');
            // ...
        }
    }
    

最新更新