从配置文件codeigniter获取日历月

Get calender month from config file codeigniter

我正在使用 codeigniter。我在配置文件中添加了我自己的月份数据,如下所示。

application/config/config.php

在配置文件中我有这样的数据

$config['months_data'] = array(1=>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

我的数据库中有一个月份名称 1,2,3。我只想将此数据替换为月份名称。 我不知道该怎么做。请给我一个逻辑。抱歉问的不是很详细。
提前致谢。

查看示例数据:

CREATE TABLE dates
    (`months` int)
;

INSERT INTO dates
    (`months`)
VALUES
    (1),
    (2),
    (3),
    (4),
    (5),
    (6),
    (7)
;

你可以通过这个查询得到你想要的:

select
date_format(str_to_date(months, '%c'), '%M')
from
dates
  • 看到它在这个 sqlfiddle
  • 中实时运行

函数的文档 str_to_date() and date_format()

您可以这样更新您的 table:

update my_table
set month_name_column = date_format(str_to_date(month_number_column, '%c'), '%M')

您将使用以下方法获取所有配置详细信息,

echo "<pre>";
$ci =& get_instance();
echo "</pre>";

使用 $ci 访问您的月份... 希望这有帮助