duanmao9918 2016-05-20 06:11
浏览 20
已采纳

如何动态更改yii常量?

I have defined some constants in yii components.

component/Interst.php

class Interst {
    Const Rate = 15.6%
    Const Service_tax_rate = 14.5%
}

I am using this in my controllers like Interest::Service_tax_rate. I want to change this rate on 31st May 2016 to 15.0% this should be active from 12 AM (at night) of 31st. How can I code so that this would change automatically after 31st night?

I have tried this in Interest.php

if(date('d/m/Y H:i:s') == '31/05/2016 00:00:00'){
    Const Service_tax_rate = 15%;
}

but this doesn't work as a condition - it's causing an error

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-05-20 06:26
    关注

    This should work:

    if(time() >= strtotime('01/06/2016 00:00:00'))
    

    Make sure you have all timestamps involved in the right format (e.g. timezone)
    See: http://php.net/manual/en/function.strtotime.php
    and: http://php.net/manual/en/function.time.php

    And don't define Service_tax_rate as Const (if you want to change it)

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

报告相同问题?

悬赏问题

  • ¥15 ADS生成的微带线为什么是蓝色空心的
  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭