我想在我的视图前端执行动作创建,站点控制器中的actionCreate代码是正确的,但是它将我重定向到index.php,其中包含此URL“http://localhost/advanced/frontend/web/index.php?Subsidize%5Bname%5D ......... ..” 知道我想在表“补贴”中创建一个新项目之后重定向到view.php
在siteController.php中创建动作
public function actionView($id) {
$model = Subsidize::findOne($id);
if ($model === null) {
throw new NotFoundHttpException;
}
return $this->render('view', [
'model' => $model,
]);
}
public function actionCreate() {
$model = new Subsidize();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->subsidize_id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
在视图“create.php”中的submitButton代码
<?= Html::submitButton($model->isNewRecord ? 'إرسال ' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
还有siteController中的函数行为
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['create'],
'rules' => [
[
'actions' => ['login', 'error'],
'allow' => true,
],
[
'actions' => ['create', 'view'],
'allow' => true,
'roles' => ['@'],
],
[
//see captcha and error added here, this fixes the issue
'actions' => ['support', 'test', 'delete', 'update', 'create', 'view'],
'allow' => true,
'roles' => ['?', '@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index' => ['get'],
'view' => ['get'],
'create' => ['get', 'post'],
'update' => ['get', 'put', 'post'],
'delete' => ['post', 'delete'],
],
],
];
}
我的观点代码:create.php
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; $model = new app\models\Subsidize; ?> <section class="support">
<div class="container">
<form class="dialog-form row">
<?php $form = ActiveForm::begin() ?>
<div class="col-md-12">
<div class="form-group">
<?php echo $form->field($model, 'name', [
'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
])->textInput()->input('name', ['placeholder' => "الإسم الكريم"])->label(false); ?>
</div><!--End Form-group-->
</div><!-- col -->
<div class="col-md-12">
<div class="form-group">
<?php echo $form->field($model, 'montant', [
'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
])->textInput()->input('montant', ['placeholder' => "المبلغ "])->label(false); ?>
</div><!--End Form-group-->
</div><!-- col -->
<div class="col-md-12">
<div class="form-group">
<?php echo $form->field($model, 'date', [
'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
])->textInput()->input('date', ['placeholder' => "تاريخ التذكير "])->label(false); ?>
</div><!--End Form-group-->
</div><!-- col -->
<div class="col-md-12">
<div class="form-group">
<?php echo $form->field($model, 'phone', [
'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
])->textInput()->input('phone', ['placeholder' => "رقم الجوال"])->label(false); ?>
</div><!--End Form-group-->
</div><!-- col -->
<div class="col-md-12">
<div class="form-group">
<?php echo $form->field($model, 'remarks', [
'inputOptions' => ['autofocus' => 'autofocus', 'class' => 'form-control transparent']
])->textInput(['rows' =>6])->input('remarks', ['placeholder' => "ملاحظات"])->label(false); ?>
</div><!-- form-group -->
</div><!-- col -->
<div class="col-md-12">
<div class="form-group" style="text-align:center ">
<?= Html::submitButton($model->isNewRecord ? 'إرسال ' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div><!-- form-group -->
</div><!-- col -->
<?php ActiveForm::end(); ?>
</form><!--End-->
</div><!-- container -->
答案 0 :(得分:1)
您是否忘记指定HTML表单的method
属性?
<form method="POST" ...>
看起来只是作为GET请求提交的表单
答案 1 :(得分:0)
对不起我以前的英语。您可以编辑帖子并添加完整的ActiveForm::begin()
代码。对于备用修复,您可以尝试删除动词行为上的创建操作,如下所示:
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index' => ['get'],
'view' => ['get'],
'update' => ['get', 'put', 'post'],
'delete' => ['post', 'delete'],
],
],