lucasvolpati / months
与月份工作的组件
1.0.0
2023-08-24 13:12 UTC
README
小巧、简单且不复杂。这是一个 HTML 生成器,您可以在项目中生成月份列表的 SELECT 元素。
安装
"lucasvolpati/months": "1.0.*"
或者运行
composer require lucasvolpati/months
文档
<?php
include __DIR__ . '/vendor/autoload.php';
use Months\Html\Generator;
echo (new Generator())->monthsSelectGenerator(
'month', //id attribute
'form-control', //classes
'reference_month'); //name attribute
?>
output:
<select id='month' class='form-control' name='reference_month'>
<option value='1'>Janeiro</option>
<option value='2'>Fevereiro</option>
...
</select>
构造参数
第一个参数是语言 - 默认为 'pt_br'
您可以通过 'en_us' 来更改月份语言为英语
<?php
include __DIR__ . '/vendor/autoload.php';
use Months\Html\Generator;
echo (new Generator('en_us'))->monthsSelectGenerator(
'month', //id attribute
'form-control', //classes
'reference_month'); //name attribute
?>
第二个参数是月份字符串格式 - 默认为 'full'
您可以将它改为 'small' 来获取简短的月份名称,例如
<?php
include __DIR__ . '/vendor/autoload.php';
use Months\Html\Generator;
echo (new Generator('pt_br', 'small'))->monthsSelectGenerator(
'month', //id attribute
'form-control', //classes
'reference_month'); //name attribute
?>
output:
<select id='month' class='form-control' name='reference_month'>
<option value='1'>Jan</option>
<option value='2'>Fev</option>
...
</select>
第三个参数是值格式 - 默认为 'number'
您可以将它改为 'string',例如
<?php
include __DIR__ . '/vendor/autoload.php';
use Months\Html\Generator;
echo (new Generator('pt_br', 'small', 'string'))->monthsSelectGenerator(
'month', //id attribute
'form-control', //classes
'reference_month'); //name attribute
?>
output:
<select id='month' class='form-control' name='reference_month'>
<option value='jan'>Jan</option>
<option value='fev'>Fev</option>
...
</select>
其他参数
您可以在主要函数上使用更多两个属性,currentSelected 和 dataAttributes,例如
<?php
include __DIR__ . '/vendor/autoload.php';
use Months\Html\Generator;
echo (new Generator())->monthsSelectGenerator(
'month', //Id attribute
'form-control', //Classes
'reference_month', //Name attribute
true, //If you want to set the current month option to selected
[
"data-some='anything'",
"data-click='getYear'"
...
] //add data attributes, as many as you need in this format
);
?>
output:
<select id='month' class='form-control' name='reference_month' data-some='anything' data-click='getYear'>
<option value='jan'>Jan</option>
<option value='fev'>Fev</option>
...
</select>
鸣谢
许可证
MIT 许可证 (MIT)。