【问题标题】:Magento admin form time fieldMagento 管理员表单时间字段
【发布时间】:2013-02-27 01:24:51
【问题描述】:

我正在尝试向管理表单添加时间字段,但它不起作用:

    $fieldset->addField('sched_time', 'time', array(
      'label'     => Mage::helper('servicemanager')->__('Scheduled Time'),
      'style'     => 'width:45px',
      'class'     => 'required-entry',
      'required'  => true,
      'name'      => 'sched_time',
      'value'  => '09,00,00',
    ));

问题如下:

  1. 数据未存储在数据库中('sched_time' 是 mysql 时间字段)
  2. 'value' 不做任何事情。我需要将默认值设置为 09:00:00(上午 9 点)

参考:http://www.excellencemagentoblog.com/magento-admin-form-field

【问题讨论】:

  • 你的时间字段'HH:MM:SS'是什么格式的?
  • 是的,格式是HH:MM:SS
  • 您为什么使用Mage::helper('servicemanager')servicemanager 是你的模块名吗?
  • 是的,servicemanager 是模块名称。

标签: forms magento magento-1.7 timefield


【解决方案1】:

您需要在控制器的 saveAction() 方法中手动编写一些代码,如下所示:

public function saveAction(){
    $id = $this->getRequest()->getParam('id');
    $model = Mage::getModel('module/model')->load($id);
    $time = $this->getRequest()->getParam('sched_time');
    $sched_time = $time[0] . ':' . $time[1] . ':' . $time[2]; //HH:MM:SS
    $model->setData('sched_time', $sched_time);
    $model->save();
}

希望这对未来的访客有所帮助!

【讨论】:

    【解决方案2】:

    你需要做一个观察者,经过几个小时试图自己找到这个我发现了这个链接magento weight attribute without decimal points

    希望对我有所帮助

    【讨论】:

      猜你喜欢
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 2014-10-23
      • 2011-08-17
      • 2015-02-07
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多