Php Pjax和表单提交未在yii2中工作
我正在开发一个注册页面,但是这个页面的某些部分应该单独提交。我做了一些研究,发现yii2中的Pjax与我在文档中发现的Pjax不能正常工作Php Pjax和表单提交未在yii2中工作,php,yii2,pjax,Php,Yii2,Pjax,我正在开发一个注册页面,但是这个页面的某些部分应该单独提交。我做了一些研究,发现yii2中的Pjax与我在文档中发现的Pjax不能正常工作 没有创建标记…只有包含csrf的隐藏元素 提交时,将重新加载所有页面 视图: 我找不到Pjax工作不正常的问题是什么,以及为什么单击“提交”按钮时重新加载所有页面。由于控制器抛出500错误,页面重新加载。 你应该改变 $model->upload() 到 $model->imageFile->upload() 在controller处理上传请求时尝试
我找不到Pjax工作不正常的问题是什么,以及为什么单击“提交”按钮时重新加载所有页面。由于控制器抛出500错误,页面重新加载。 你应该改变
$model->upload()
到
$model->imageFile->upload()
在controller处理上传请求时尝试捕获更多问题提交按钮…提交主表单…我不知道为什么。顺便说一句,我需要使用yii和pjax上传文件…这就是我试图实现的。没关系。只需添加更多表单属性:multipart/form data,然后您就可以从controllerfirst获取文件,检查正常的post条件,如$model->load(Yii::$app->request->post()
<div class="row profileimg">
<?php Pjax::begin(['timeout' => 40000, 'id' => 'myPjax',]); ?>
<?= Html::beginForm(['couple-partner/saveprofileimg'], 'post', ['id' => 'CouplePartnerSumb', 'data-pjax' => true, 'class' => 'form-inline']); ?>
<div class="col-lg-12" onmouseover="onmouseOverImg('FirstPartnerEditButton', 'FirstPartnerDelButton');" onmouseout="onmouseoutImg('FirstPartnerEditButton', 'FirstPartnerDelButton')" id="imgdiv" style="display:inline-block;position: relative;left : 35%;height: 110px;width: 150px;">
<img src="<?= $models != NULL && sizeof($models) > 0 && $models[0]->USER_PROFILE_PIC != NULL ? $models[0]->USER_PROFILE_PIC : "" ?>" style="cursor: pointer;width:100%;height:100% " id="firstPartnerProfilePic" class="img-thumbnail ">
<?= Html::fileInput('imageFile', '') ?>
<?php echo Html::submitButton('Upload', ['class' => 'btn btn-primary', 'id' => 'submit_iddddd',]) ?>
</div>
<?php echo Html::endForm();Pjax::end();?>
</div>
public function actionSaveprofileimg() {
$model = new CouplePartner();
if (Yii::$app->request->isAjax) {
$model->imageFile = UploadedFile::getInstance($model, 'imageFile');
if ($model->upload()) {
// file is uploaded successfully
return;
}
}
return $this->renderAjax('index', ['model' => $model]);
}