How to pass php variable to PluginEvent config Sli

2019-08-27 18:27发布

问题:

I use Slider Kartik extension for Yii2. There is PluginEvent options, that i want to config to my needs. So here is my code:

<?php echo Slider::widget([
    'name'=>'rating_1',
    'value'=>7,
    'sliderColor'=>Slider::TYPE_GREY,
    'pluginEvents' => [
        'slide' => "function(slideEvt) { 
            $('#testVal. ').text(slideEvt.value); 
        }",
    ],
]);
?>
<span>Current Slider Value: <span id="testVal">3</span></span>

But in my HTML layout i used models attribute like: $value['strategy_title'] Is there is the way to put my $value['strategy_title'] instead of #testVal?

回答1:

You need to concatenate php variable,

<?= Slider::widget([
   'name' => 'rating_1',
   'value' => 7,
   'sliderColor' => Slider::TYPE_GREY,
   'pluginEvents' => [
       'slide' => "function(slideEvt) { 
           $('#".$value['strategy_title']."').text(slideEvt.value); 
       }",
   ],
]) ?>


标签: php yii2