How can I access the variable in model sent by post method from view file in yii?

I have did the following so far my view file where I am sending my data to model, tariffCardType, jobType, clothType, newRegularRate, newUrgentRate are all JavaScript variables which I have to send as data

tariffcard.php(view)

function saveRates(btnId, regularValue, urgentValue)
  {
    var clothType = btnId.substring(0, btnId.indexOf("-"));
    var tariffCardType = btnId.substring(btnId.indexOf("-")+1, btnId.indexOf("-", btnId.indexOf("-")+1));
    var jobTypeCode = btnId.substring(btnId.indexOf("-", btnId.indexOf("-")+1)+1, btnId.length); 
    var jobType = "iron";
    <?php
    echo CHtml::ajax(array(
            'url'=>  CController::createUrl("site/UpdateRates"),
            'type'=>'get',
            'data' => "{tarifftardtype:tariffCardType, jobtype:jobType, clothtype:clothType, newregularrate:newRegularRate, newurgentrate:newUrgentRate}",
            'success'=> "function(html){document.getElementById('demo').innerHTML = html;}",
    ))
    ?>
  }

I am trying to access the data in model as follow

TariffCardForm.php(model)

public function updateTariffRates()
{
    $response["tariffcardtype"] = Yii::$app->request->getPost('tarifftardtype');
    $response["jobtype"] = Yii::$app->request->getPost('jobtype');
    $response["clothtype"] = Yii::$app->request->getPost('clothtype');
    $response["newregularrate"] = Yii::$app->request->getPost('newregularrate');
    $response["newurgentrate"] = Yii::$app->request->getPost('newurgentrate');

    return $response;
}

The method I am using is it correct to access the data in model? Also how can I send the javascript variables as a data in php array?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s