yii2 - dynamicform wbraganca : What's wrong with my code -
after submit request, go blank page. please check code. thanks. i'm using yii2 framework , wbraganca dynamic form plugin.
public function actioncreate() { $model = new purchaseorder(); $details = [ new purchaseorderdetail ]; $seq = sequence::findone(['id' => 'po', 'name' => (int)date('ymd')]); if(is_null($seq)){ $_seq = new sequence(); $_seq->id = 'po'; $_seq->name = (int)date('ymd'); $_seq->value = 0; $_seq->save(); $model->id = $_seq->id . '/' . $_seq->name . '/' .str_pad($_seq->value+1, 3, "0", str_pad_left); } else { $seq->value += 1; $model->id = $seq->id . '/' . $seq->name . '/' . str_pad($seq->value, 3, "0", str_pad_left); $seq->update(); } $model->trx_date = date('y-m-d'); if ($model->load(yii::$app->request->post())) { $details = model::createmultiple(purchaseorderdetail::classname()); model::loadmultiple($details, yii::$app->request->post()); //assign po_id foreach($details $detail){ $detail->oid = uniqid(); $detail->po_id = 0; } // ajax validation if(yii::$app->request->isajax){ yii::$app->response->format = response::format_json; return arrayhelper::merge( activeform::validatemultiple($details), activeform::validate($model) ); } // validate models $valid1 = $model->validate(); $valid2 = model::validatemultiple($details); $valid = $valid1 && $valid2; if($valid){ $trx = \yii::$app->db->begintransaction(); try { // save master record if($flag = $model->save(false)){ // save detail records foreach($details $detail){ $detail->po_id = $model->id; if(!($flag = $detail->save(false))){ $trx->rollback(); break; } } } if($flag){ //if success commit transaction //then view result $trx->commit(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, 'details' => $details ]); } } catch(exception $ex){ // transaction failed, rollback $trx->rollback(); throw $ex; } } } else { return $this->render('create', [ 'model' => $model, 'details' => $details ]); } }
when click create button, redirect blank page , check log, didn't generate error log. here logs
routing name value route 'purchase-order/create' action 'app\\controllers\\purchaseordercontroller::actioncreate()' parameters [] $_get empty. $_post name value _csrf 'a0hcehjolxebegy.c15vxd0ydbeilvsvpsq2ouqsdqs0mcothw1qqg==' purchaseorder [ 'id' => 'po/170407/024' 'trx_date' => '2017-04-07' 'supplier_id' => '1' 'remark' => 'test remark' 'total' => '1500000' ] purchaseorderdetail [ 0 => [ 'item_id' => '1' 'qty' => '10' 'price' => '150000' 'total' => '1500000' 'remark' => 'aa' ] ] $_files empty. $_cookie name value _csrf 'c3c290ca6c2fdb8a905c1692baebc21ba6a5715325855d6e863a91f1cd5cd5c7a:2:{i:0;s:5:\"_csrf\";i:1;s:32:\"pzdfy6b-vz6ipevdvlta6zxz_xhkmeg3\";}' phpsessid 'o1337j64mptbjhptr2o3dcl5k7' request body name value content type 'application/x-www-form-urlencoded' raw '_csrf=a0hcehjolxebegy.c15vxd0ydbeilvsvpsq2ouqsdqs0mcothw1qqg%3d%3d&purchaseorder%5bid%5d=po%2f170407%2f024&purchaseorder%5btrx_date%5d=2017-04-07&purchaseorder%5bsupplier_id%5d=1&purchaseorder%5bremark%5d=test+remark&purchaseorderdetail%5b0%5d%5bitem_id%5d=1&purchaseorderdetail%5b0%5d%5bqty%5d=10&purchaseorderdetail%5b0%5d%5bprice%5d=150000&purchaseorderdetail%5b0%5d%5btotal%5d=1500000&purchaseorderdetail%5b0%5d%5bremark%5d=aa&purchaseorder%5btotal%5d=1500000' decoded params [ '_csrf' => 'a0hcehjolxebegy.c15vxd0ydbeilvsvpsq2ouqsdqs0mcothw1qqg==' 'purchaseorder' => [ 'id' => 'po/170407/024' 'trx_date' => '2017-04-07' 'supplier_id' => '1' 'remark' => 'test remark' 'total' => '1500000' ] 'purchaseorderdetail' => [ 0 => [ 'item_id' => '1' 'qty' => '10' 'price' => '150000' 'total' => '1500000' 'remark' => 'aa' ] ] ]
please help. before
this question resolve skipping validation on foreign key this
[['item_id'], 'exist', 'skiponerror' => true, 'targetclass' => item::classname(), 'targetattribute' => ['item_id' => 'id']],
Comments
Post a Comment