2016-12-29 55 views
0

沃金我正在开发一个注册页面,但该页面的某些部分应单独提交。我做了一些研究,发现PJAX在yii2 ut我发现在文档中与我的工作不正常。Pjax和表单提交不yii2

  1. 没有标签创建...只有一个隐藏的元素包含csrf。
  2. 提交时,所有页面都重新加载。

查看:

<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]); 
} 

我找不到那是什么Pjax不能正常工作的问题,为什么提交按钮重新加载所有的页面点击时。

+0

第一次检查正常后置条件类似$模型 - >负载(的Yii :: $ APP->请求 - >后( ) –

回答

0

重新加载,因为控制器抛出500错误页面。 你应该改变 $model->upload() $model->imageFile->upload() 并试图捕捉更多的问题,同时控制器处理上传请求

+0

提交按钮...提交的主要形式...我不知道为什么。 –

+0

顺便说一句,我需要使用Yii和pjax ......这就是我想实现上传文件。 –

+0

这没关系。只需添加更多的形式属性:multipart/form-data然后你可以从控制器获取文件 –