dth34653 2011-10-21 16:13
浏览 14
已采纳

Symfony PHP - 日期窗口小部件格式和数据库日期字段

I have a form where I have widget like this:

  $this->widgetSchema['valid_to'] 
          = new sfWidgetFormDate(array('format'=>'%day%/%month%/%year%','years'=>range('1990',date('Y')+5)), array());

Unfortunately the date format also caused that it tries to save date with that format into database which of course is bad.

Can anyone tell how to repair this?

Thanks in advance Gabe

  • 写回答

1条回答 默认 最新

  • duan19750503 2011-10-23 10:11
    关注

    I'm using this solution, settings and code, in my backend that you can easily fit to your project.

    In apps/backend/config/settings.yml:

     all:
      .settings:
        default_culture: it_IT
        i18n:            on
    

    In apps/backend/i18n/messages.it.xml

    <?xml version="1.0" ?>
    <xliff version="1.0">
      <file original="global" source-language="it" datatype="plaintext">
        <body>
          <trans-unit id="1">
            <source>Hello</source>
            <target>Ciao</target>
          </trans-unit>
          <trans-unit id="2">
            <source><![CDATA[%month% %day% %year%]]></source>
            <target><![CDATA[%day% %month% %year%]]></target>
          </trans-unit>
        </body>
      </file>
    </xliff>
    

    In date widget this format:

    'format' => sfContext::getInstance()->getI18N()->__('%month% %day% %year%')
    

    The date will be saved in the format yyyy-mm-dd but displayed in the culture you setted up.

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

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导