Yii2 如何向Kartik DetailView添加标签提示
我正在使用Kartik DetailView,希望在用户将鼠标悬停在标签上时显示提示(如GII表单)。我试过以下方法,但不起作用Yii2 如何向Kartik DetailView添加标签提示,yii2,Yii2,我正在使用Kartik DetailView,希望在用户将鼠标悬停在标签上时显示提示(如GII表单)。我试过以下方法,但不起作用 $attributes = [ [ 'attribute'=>'name', 'inputWidth'=>'50%', ], [ 'attribute'=>'round_precision', 'hint' => 'Specify the number of decimal di
$attributes = [
[ 'attribute'=>'name',
'inputWidth'=>'50%',
],
[ 'attribute'=>'round_precision',
'hint' => 'Specify the number of decimal digits after the decimal to round to. Use a negative value to round the integer part of the number to the number of digits before the decimal. A value of 1 will round 1.855 to 1.7, and a value of -2 will round 1.855 1.86. A value of -1 will round 17.6 to 18, and a value of -2 will round 17.6 to 20.',
'inputWidth'=>'10%',
],
];
如何在Kartik DetailView小部件中获得类似Gii的提示?看来Gii只是在使用引导弹出窗口。我按照上的说明操作,然后开始使用帮助弹出框创建标签 我创建了以下函数来呈现标签
/**
* Create a help popover to be shown on an input form.
* @param $label string The label to display for the input.
* @param $help string The help text to display.
* @return string
*/
public static function renderLabelHelp($label, $help) {
return Html::tag('span', $label, [
'data-toggle'=>'popover',
'data-trigger' => 'click hover',
'data-placement' => 'auto right',
'data-html' => 'true', // allow html tags
'data-title'=> 'Field Help',
'data-content'=>$help,
'style'=>'text-decoration: underline; cursor:help;'
]);
}
然后我用这样的方法调用函数
<?= Html::label(MyHelpers::renderLabelHelp(
$model->getAttributeLabel('round_precision'),
'Specify the number of decimal digits after the decimal to round to.<br>Use a negative value to round the integer part of the number to the number of digits before the decimal.<br>A value of 1 will round 1.855 to 1.7, and a value of -2 will round 1.855 1.86. A value of -1 will round 17.6 to 18, and a value of -2 will round 17.6 to 20.'
) ?>
yii2模型类中的
具有良好的方法attributeHints()
你可以用这个
'hint' => $model->getAttributeHint('round_precision')
'hint' => $model->getAttributeHint('round_precision')