Teg*_*der 1 php zend-framework magento
在Magento我正在创建一个自定义模块,并希望能够通过datetime列自动过滤,以便初始网格列表仅显示与"今天"日期相关的实体.
这是我的日期时间列:
$this->addColumn('ts', array(
'header' => $hlp->__('Activated'),
'align' => 'left',
'index' => 'ts',
'type' => 'datetime',
'width' => '160px',
));
Run Code Online (Sandbox Code Playgroud)
我认为应该有一种方法让我像这样添加一个过滤器到集合中:
$now = Mage::getModel('core/date')->timestamp(time());
$dateTime = date('m/d/y h:i:s', $now);
$collection = Mage::getModel('mymodule/items')->getCollection()
->addFieldToFilter('ts', $dateTime);
Run Code Online (Sandbox Code Playgroud)
但这不起作用?
我使用了错误的过滤器吗?数据库中的"ts"字段是"datetime"字段,但默认的magento"From:" - "To:"日期范围选择器不使用小时,分钟,秒.
有任何想法吗?
谢谢,特根
这似乎有效.我的时间格式不正确.
$now = Mage::getModel('core/date')->timestamp(time());
$dateStart = date('Y-m-d' . ' 00:00:00', $now);
$dateEnd = date('Y-m-d' . ' 23:59:00', $now);
$collection = Mage::getModel('mymodule/items')->getCollection()
->addFieldToFilter('ts', array('from' => $dateStart, 'to' => $dateEnd));
Run Code Online (Sandbox Code Playgroud)