这是我的行动:
public function actionRend()
{
$model = new RentForm();
$parameter = Yii::$app->request->get('id');
$query = Cars::findOne(['description' => $parameter]);
$query = Car_rend_tariffs::find()->where(['car' => $query->id])->all();
$rend = [];
$i=0;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$seconds = strtotime($model->start_time);
$seconds_2 = strtotime($model->end_time);
$seconds = ($seconds_2 - $seconds)/3600;
$seconds = ceil($seconds);
if ($seconds < 1) {
$error_message = "Время аренды не может быть меньше часа";
return $this->render('rend',[
'model' => $model,
'seconds' => $seconds,
'error' => $error_message
]);
}
$query = Cars::findOne(['description' => $parameter]);
$query_rent = Car_rend_time::find()->where('min_use_time <= :min_use_time and max_use_time >= :max_use_time',['min_use_time' => $seconds,'max_use_time' => $seconds])->one();
$query_tariff = Car_rend_tariffs::findOne(['car' => $query->id,'car_rend_time' => $query_rent->id]);
$tariff_view = Car_rend_tariff_views::findOne(['id' => $query_tariff->tariff]);
$sum = $tariff_view->min_cost + ($seconds - $query_rent->min_use_time)*$tariff_view->additional_hour_cost;
$payment = new PaymentForm();
return $this->render('payment',[
'model' => $payment,
'service' => $query_tariff,
'sum' => $sum
]);
}
return $this->render('rend',[
'model' => $model
]);
}
这些是我配置中的UrlManager规则:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'main/default/index',
'<_a:error>' => 'main/default/<_a>',
'<_a:(login|logout)>' => 'admin/default/<_a>',
'<_a:(admin)>' => 'admin/default/login',
'<_a:(flight)>' => 'main/service/flight',
'<_a:(auto)>' => 'main/service/auto',
'<_a:(rend)>' => 'main/service/rend',
'<_a:(payment)>' => 'main/service/payment',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<id:\d+>' => '<_m>/<_c>/view',
'<_m:[\w\-]+>/<_c:[\w\-]+>/<_a:[\w\-]+>/<id:\d+>' => '<_m>/<_c>/<_a>',
'<_m:[\w\-]+>' => '<_m>/default/index',
'<_m:[\w\-]+>/<_c:[\w\-]+>' => '<_m>/<_c>/index',
],
],