duanlei8119 2017-06-05 00:58
浏览 65
已采纳

Laravel 5.4中未定义的常量

I am migrating an old code from 4.2 to 5.4. My index.php is triggering the error: undefined constant CURRENCY_BEFORE assumed 'CURRENCY_BEFORE

from this line:

<select name="curreny_position">
    <option value="BEFORE"
    <?php if ($curr_pos['value'] == CURRENCY_BEFORE) echo "selected"; ?>> 
     Before
    </option>
    <option value="AFTER" <?php if ($curr_pos['value'] == CURRENCY_AFTER) echo "selected"; ?>>After
    </option>

I am not sure if this would help, but this is the callout in my settings.php file:

{
    $currency_position = self::param('site', 'curr_position')['value'];
    $currency = self::param('site', 'currency')['value'];
    switch ($currency_position) {
        case CURRENCY_BEFORE:
            return implode(' ', [$currency, number_format($amount, 2)]);
            break;
        case CURRENCY_AFTER:
            return implode(' ', [number_format($amount, 2), $currency]);
            break;
 }

what would be the proper way to define CURRENCY_BEFORE above?

  • 写回答

1条回答 默认 最新

  • dongzhan1570 2017-06-05 05:04
    关注

    I would suggest moving the definition of your constant to a config file

    <?php
    /**
     *  file: app/config/constants.php
     */
    
    return [
        'CURRENCY_BEFORE' => 'BEFORE'
    ];
    

    then you can call anywhere in the application by Config::get('constants.CURRENCY_BEFORE')

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里