在 roompage.php 页面上,我有以下数据:
<?php $form = ActiveForm::begin(['action' =>['site/checkout'],'method' => 'POST']); ?>
<?= $form->field($model, 'room_type')->hiddenInput(['value'=>$data->room_type])->label(false); ?>
<?= $form->field($model, 'rate')->hiddenInput(['value'=>$data->rate])->label(false); ?>
<?= Html::submitButton('CHECKOUT', ['class' => 'button btn btn-default']) ?>
<?php ActiveForm::end(); ?>
我需要将此数据传递到checkout.php
页面如何执行此操作?我可以通过URL发送数据吗?如果是,那么如何做到这一点或以其他任何方式做同样的事情?
public function actionCheckout()
{
$model = new CreateBookings();
$data = Yii::$app->request->post();
if(isset($data['DynamicModel']))
{
$room_type = $data['DynamicModel']['room_type'];
}
if ($model->load(Yii::$app->request->post()))
{
$model->save();
return $this->redirect('confirmation');
}
else
{
return $this->render('checkout', [
'model' => $model,'room_type' => $room_type]);
}
}
public function actionRoompage($room_id)
{ $model = new \yii\base\DynamicModel(['room_type','rate']);
$searchModel = new RoomTypesSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$data = RoomTypes::find()->where(['room_id' => $room_id])->one();
return $this->render('roompage', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
'data' => $data,
]);
}
需要将数据从actionRoompage()
传递到actionCheckout()
答案 0 :(得分:0)
在这种情况下,您应该使用POST
请求将一些数据发送到另一个页面。在actionCheckout
中,您已准备好获取POST
数据并将其加载到模型$model->load(Yii::$app->request->post())
您还需要在视图roompage.php
中创建表单
例如,在actionRoompage
中也可以创建$model = new CreateBookings();
而不是在视图中显示输入(你可以隐藏它们):
<?php $form = ActiveForm::begin(['id' => 'checkout-form']); ?>
<?php echo $form->field($model, 'quantity') ?>
<?php echo $form->field($model, 'email') ?>
<?php echo Html::submitButton(Yii::t('frontend', 'Login'), ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
<?php ActiveForm::end(); ?>