我想在我看来执行动作创建,actionCreate在现场控制器中的代码是正确的,但是它用这个url“http://localhost/advanced/frontend/web/index.php?Subsidize%5Bname%5D.”将我重定向到index.php知道在创建表“补贴”中的新项目后,我想重定向到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,
]);
}
}查看“submitButton”中的create.php代码
<?= 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 -->
发布于 2017-06-06 07:18:30
忘记指定HTML的method属性了吗?
<form method="POST" ...>看起来表单只是作为GET请求提交的。
发布于 2017-06-06 07:32:36
以前我的英语很抱歉。你能编辑你的文章并添加完整的ActiveForm::begin()代码吗?对于替代修复,您可以尝试删除对谓词行为的create操作,如下所示:
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index' => ['get'],
'view' => ['get'],
'update' => ['get', 'put', 'post'],
'delete' => ['post', 'delete'],
],
],https://stackoverflow.com/questions/44383589
复制相似问题