1

i use kartik-v/yii2-slider in my project .

with this code i added one slider A range select : enter image description here

echo '<b class="badge">$10</b> ' . Slider::widget([
    'name'=>'rating_3',
    'value'=>'250,650',
    'sliderColor'=>Slider::TYPE_GREY,
    'pluginOptions'=>[
        'min'=>10,
        'max'=>1000,
        'step'=>5,
        'range'=>true
    ],
]) . ' <b class="badge">$1,000</b>';

i have 2 column for min value and max value in (set_money) table : min_money max_money

how i can save thats variable in my database !

I do not know how to get that variable in controller

Saltern
  • 1,305
  • 2
  • 16
  • 42
  • 1
    After you send your form data to your controller you will be able to get it in Yii::$app->request->get('rating_3') or Yii::$app->request->post('rating_3') , depending on method you sending data from form. So in controller try to handle form submit with if(Yii::$app->request->post('rating_3')) // process data and save it to DB – Volodymyr Sitdikov Feb 06 '16 at 09:43

1 Answers1

1

in view file, in form

<?php
echo '<b class="badge">$10</b> ' . Slider::widget([
    'name'=>'min_money',
    'value'=>'250,650',
    'sliderColor'=>Slider::TYPE_GREY,
    'pluginOptions'=>[
        'min'=>10,
        'max'=>1000,
        'step'=>5,
        'range'=>true
    ],
]) . ' <b class="badge">$1,000</b>';

in controller

public function actionCreate()
{
    $model = new Model; // give your actual model name instead of Model
    if($model->load(Yii::$app->request->post()))
    {
        list($model->min_money, $model->max_money) = explode(',', $model->min_money);
        // now both $model->min_money and $model->max_money are set and contains value submitted in form by Kartik Slider Widget
        if($model->save(true))
        {
            // success -> redirect
        }
        else
        {
            // error render to form again
        }

    }
}
Sohel Ahmed Mesaniya
  • 3,344
  • 1
  • 23
  • 29