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')

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?