dqn48247 2015-01-28 12:34
浏览 316
已采纳

Laravel - 有全局变量吗?

I am using Laravel. I have referenced my project name in several different places in my views.

I then decided to change the name of my application! So is there a global variable I can use instead and then I only have to change the name in one place next time?

I looked through the docs but couldn't see this feature..

  • 写回答

2条回答 默认 最新

  • dongyuling0312 2015-01-28 13:39
    关注

    Of course global variables exist in Laravel as well. However just because the exist it doesn't mean you should use them.

    A much more suitable approach would be to store the name in a config file.

    You can use app/config/app.php and just add a row:

    return array(
        'name' => 'FooBar',
        // existing values ...
        'debug' => false,
        'url' => 'http://localhost',
        // etc ...
    );
    

    Or create your very own config file. For example app/config/site.php

    return array(
        'name' => 'FooBar'
    );
    

    And you use it like this:

    Config::get('app.name');
    

    Or

    Config::get('site.name');
    

    See the documentation for more information

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端