我有问题从URL参数到我的Yii 2模型。
网址:https://example.com/?key=test&id=1234
我的代码是:
public function save()
{
$httpClient = new Client();
$keyword = Yii::$app->getRequest()->getQueryParam('key');
$data = [
'civilite' => $this->civility,
'nom' => $this->lastName,
'prenom' => $this->firstName,
'telephone' => $this->phoneNumber,
'email' => $this->emailAddress,
'operateur' => $this->operator,
'tel_domicile' => $this->phone,
'keyword' => $keyword,
];
$preferences = explode(',', $this->preferences);
$index = 0;
foreach ($preferences as $preference) {
$index++;
$data['attente' . $index] = $preference;
}
LeadLogHelper::log($data);
$rawResponse = $httpClient->createRequest()
->setMethod('POST')
->setUrl(\Yii::$app->params['leadWebserviceUrl'])
->setData($data)
->send();
$response = json_decode($rawResponse->content);
if (!$response->Statut) {
Yii::error('An error occurred while saving the data using the webservice', __METHOD__);
Yii::error($data, __METHOD__);
Yii::error($response, __METHOD__);
}
return $response->Statut == 1 || $response->Message === 'La Fiche existe déjà.';
}
保存功能正常工作,但$Keyword的值为空,请帮助!!
1条答案
按热度按时间tmb3ates1#
取决于您的查询链接,如:
https://example.com/?key=test&id=1234
在调用
$model->save()
方法时,特别是对于此特定模型,可以传递一个附加参数作为$key
,如下所示:方法1
以下是模型:
但是,使用如下模型属性是安全的:
方法2
然后你可以在控制器中使用这个:
在您的模型中进行变更:
然后调用
$model->save()
方法。希望这对你有帮助。