duanfei8149 2015-10-15 21:46
浏览 110
已采纳

Laravel 5中应该在哪里存储配置值数组?

I have an array of Google Font settings that looks like this:

$googleFontList = array(
    'Abril Fatface' => array(
        'link_code' => 'Abril+Fatface',
        'css_name' => 'Abril Fatface',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Archivo Narrow' => array(
        'link_code' => 'Archivo+Narrow:400italic,400,700italic,700',
        'css_name' => 'Archivo Narrow',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Arvo' => array(
        'link_code' => 'Arvo:400italic,400,700italic,700',
        'css_name' => 'Arvo',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Crete Round' => array(
        'link_code' => 'Crete+Round:400italic,400',
        'css_name' => 'Crete Round',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Droid Serif' => array(
        'link_code' => 'Droid+Serif:400italic,400,700italic,700',
        'css_name' => 'Droid Serif',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Josefin Slab' => array(
        'link_code' => 'Josefin+Slab:400,400italic,700,700italic',
        'css_name' => 'Josefin Slab',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Lato' => array(
        'link_code' => 'Lato:400italic,400,700,700italic',
        'css_name' => 'Lato',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Merriweather' => array(
        'link_code' => 'Merriweather:400italic,400,700italic,700',
        'css_name' => 'Merriweather',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Open Sans' => array(
        'link_code' => 'Open+Sans:400,400italic,700italic,700',
        'css_name' => 'Open Sans',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Oswald' => array(
        'link_code' => 'Oswald:400,700',
        'css_name' => 'Oswald',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Roboto' => array(
        'link_code' => 'Roboto:400,400italic,700,700italic',
        'css_name' => 'Roboto',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Roboto Condensed' => array(
        'link_code' => 'Roboto+Condensed:400,400italic,700,700italic',
        'css_name' => 'Roboto Condensed',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Roboto Slab' => array(
        'link_code' => 'Roboto+Slab:400,400italic,700,700italic',
        'css_name' => 'Roboto Slab',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Ubuntu' => array(
        'link_code' => 'Ubuntu:400,400italic,700,700italic',
        'css_name' => 'Ubuntu',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
    'Varela Round' => array(
        'link_code' => 'Varela+Round',
        'css_name' => 'Varela Round',
        'normal_weight' => 400,
        'bold_weight' => 700,
    ),
);

I would like to avoid having to place this array in multiple different controller methods. Where could/should I put something like this so that it can later be called into controllers? Could this live in a config file?

  • 写回答

1条回答 默认 最新

  • doulu8537 2015-10-15 21:53
    关注

    You can generate a new config file, e.g. data.php in config folder .Just return an array like this:

    <?php
    
    return [
        'key' => 'value',
    ];
    

    You can get this variable by

    Config::get('data.key');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥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做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序