Magento 后台配置中实现日期选择 (Date picker)

首先,创建一个新的Form Field 类:

<?php
class Glamour_Glscore_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$date = new Varien_Data_Form_Element_Date;
$format = 'yyyy-MM-dd HH:mm:ss';

$data = array(
'name' => $element->getName(),
'html_id' => $element->getId(),
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'time' => true
);
$date->setData($data);
$date->setValue($element->getValue(), $format);
$date->setFormat('yyyy-MM-dd HH:mm:ss');
$date->setForm($element->getForm());

return $date->getElementHtml();
}
}


在system.xml中使用新的Field类:


<start_date>
<label>Start Date</label>
<frontend_type>text</frontend_type>
[b]<frontend_model>Glamour_Glscore_Block_Adminhtml_System_Config_Date</frontend_model>[/b]
<validate>validate-date</validate>
<sort_order>4</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</start_date>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Magento 2 ,您可以使用 Redis 作为缓存后端以提高网站性能。以下是在 Magento 2 配置 Redis 的步骤: 1. 安装 Redis: 在 Ubuntu 上,您可以使用以下命令安装 Redis: ``` sudo apt-get update sudo apt-get install redis-server ``` 您可以在其他操作系统上使用适当的命令安装 Redis。 2. 安装 Redis PHP 扩展: 您需要安装 Redis PHP 扩展才能在 Magento 2 使用 Redis 缓存后端。您可以使用以下命令在 Ubuntu 上安装 Redis PHP 扩展: ``` sudo apt-get install php-redis ``` 您可以在其他操作系统上使用适当的命令安装 Redis PHP 扩展。 3. 在 Magento 2 配置 Redis: 在 Magento 2 配置 Redis 缓存后端需要编辑 `app/etc/env.php` 文件。使用以下命令打开该文件: ``` sudo nano /var/www/html/app/etc/env.php ``` 在该文件,找到以下行: ``` 'cache' => [ 'frontend' => [ 'default' => [ 'backend' => 'Magento\Framework\Cache\Backend\File', 'frontend' => 'Magento\Framework\Cache\Frontend\Decorator\TagScope', 'frontend_options' => [ 'cache_id_prefix' => 'mage', ], ], 'page_cache' => [ 'backend' => 'Magento\Framework\Cache\Backend\File', 'frontend' => 'Magento\Framework\Cache\Frontend\Decorator\TagScope', 'frontend_options' => [ 'cache_id_prefix' => 'mage', ], ], ], ], ``` 替换上述 `cache` 部分的内容,使其与以下内容匹配: ``` 'cache' => [ 'frontend' => [ 'default' => [ 'backend' => 'Cm_Cache_Backend_Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'port' => '6379', 'database' => '0', 'password' => '', 'compress_data' => '1', 'compression_lib' => 'gzip', 'persistent' => '', 'force_standalone' => '0', 'connect_retries' => '1', 'read_timeout' => '10', 'automatic_cleaning_factor' => '0', 'compress_tags' => '1', 'prefix' => '', 'serializer' => '', ], 'frontend' => 'Magento\Framework\Cache\Frontend\Decorator\TagScope', 'frontend_options' => [ 'cache_id_prefix' => 'mage', ], ], 'page_cache' => [ 'backend' => 'Cm_Cache_Backend_Redis', 'backend_options' => [ 'server' => '127.0.0.1', 'port' => '6379', 'database' => '1', 'password' => '', 'compress_data' => '0', 'compression_lib' => '', 'persistent' => '', 'force_standalone' => '0', 'connect_retries' => '1', 'read_timeout' => '10', 'automatic_cleaning_factor' => '0', 'compress_tags' => '1', 'prefix' => '', 'serializer' => 'None', ], 'frontend' => 'Magento\Framework\Cache\Frontend\Decorator\TagScope', 'frontend_options' => [ 'cache_id_prefix' => 'mage', ], ], ], ], ``` 在上述代码,您需要更改以下内容: - `'server' => '127.0.0.1'`:更改为您的 Redis 服务器的 IP 地址或主机名。 - `'port' => '6379'`:更改为您的 Redis 服务器的端口号。 - `'database' => '0'` 和 `'database' => '1'`:更改为您要在 Redis 使用的数据库的编号。 4. 清除 Magento 2 缓存: 使用以下命令清除 Magento 2 缓存: ``` php bin/magento cache:clean ``` 现在,您已经成功地在 Magento 2 配置了 Redis 缓存后端。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值