Gridview and input

.

Will the user be submitting the value and reloading the page to calculate the new value? If so you can pass the value in from a form to the controller like this:




//found this at http://www.yiiframework.com/forum/index.php/topic/64351-how-to-get-post-value-in-a-controller/

$request=Yii:$app->request->post('name_you_gave_the_form')['name_you_gave_the_input_field']; //For PHP > 5.4

//or for PHP < 5.4 :

$post =Yii::$app->request->post('name_you_gave_the_form');

$request = $post['name_you_gave_the_input_field'];



Inside of a controller it might look like this




public function actionYourAction()

{

    $theValueYouWant = Yii::$app->request->post('name_you_gave_the_form_input')['name_you_gave_the_input_field'];

    return $this->render('viewWithTheGridViewWidget', [

        'theValueYouWant' => $theValueYouWant,

    ]);

}



This will let you use the variable $theValueYouWant inside of your view.

Otherwise if you want the value to be dynamic and change as the user types then you’ll have to do something with javascript.

Maybe output the value as a ‘<div id="the_value>’ . $temp . ‘</div>’ and then hook the value up to an input form via javascript.

Thanks :) I already fixed this problem this way

view/index


<div class="currency-index">


    <h1><?= Html::encode($this->title) ?></h1>


    <?php $glob = (double)$searchModel->euro ?>


    <?php  echo $this->render('_search', ['model' => $searchModel]); ?>


    <?= HTML::a('<h4>'.$searchModel->date.'</h4>')?>

    

    <?= GridView::widget([

            'dataProvider' => $dataProvider,

            'summary'=> '',

            'columns' => [

//                    'date',

                'name',

                'course',

                [

                    'attribute' => $searchModel->euro . ' Euro',

                    'value' => 'euro',

                    'format' => 'raw',

                    'filterInputOptions' => [

                        'class' => 'form-control input-sm',

                    ],

                    'value' => function ($model) use ($glob)

                    {

                        $temp = number_format((float)($model->course * $glob), 2, '.', '');

                        return Html::encode($temp . ' ' . $model->name . ' ' );

                    },

                ],

            ],

        ]

    ); ?>

</div>

and public $euro in model currency

Now I’m trying to use js and pjax for submit without refresh