How can i get form->field() value? -


in short, have following code:

<?= $form->field( $isntmodel, 'id')->textinput() ?> <?= html::a('<i class="mdi-action-done"></i>', ['add-item', 'id' => ???], [     'class' => 'btn-btn-add pull-right', ]) ?> 

this code wrong.

so. need value input user. , set instead ???

$form->field() must have $model, $attribute, $options = []. how can write field not using $model , $attribute? not table column, need value , set instead ???

i try that

  public function actionadditem($id) {     $model = $this->$model;     $product = product::findone($id);     $orderitem = new orderitem();     $orderitem->order_id = $model->id;     $orderitem->title = $product->title;     $orderitem->price = $product->getprice();     $orderitem->product_id = $product->id;     $orderitem->save();     return $this->redirect(['index']);   } 

but throws exception. @ row $model = $this->$model , , don't know how field submit id link

adding item work if put in browser http://yii2-shop/backend/web/order/add-item?modelid=13&id=1&quantity=4

upd

now form looks

<?php $form = activeform::begin([]); ?>     <tr>         <td><?= $n ?></td>         <td><?= $form->field( $model, 'neworderitemid')->textinput()->label(false) ?></td>         <td></td>         <td></td>         <td class="text-center"><?= $form->field( $model, 'neworderitemquantity')->textinput()->label(false) ?></td>         <td>             <?= html::a('<i class="mdi-action-done"></i>', [                 '/order/add-item',                 'modelid' => $model->id,                 'id' => $model->neworderitemid,                 'quantity' => $model->neworderitemquantity,             ], [               'class' => 'btn btn-add pull-right',               'data-toggle'=>'tooltip' ,               'data-placement'=>'bottom',               'title'=>'Добавить товар',             ]) ?>         </td>     </tr> <?php activeform::end(); ?> 

and add-item looks like

public function actionadditem($modelid, $id, $quantity) {     $model = $this->findmodel($modelid);     $product = product::findone($id);     $orderitem = new orderitem();     $orderitem->order_id = $model->id;     $orderitem->title = $product->title;     $orderitem->price = $product->getprice();     $orderitem->product_id = $product->id;     $orderitem->quantity = $quantity;     $orderitem->save();     return $this->redirect(['index']); } 

neworderitemid , neworderitemquantity public variables mark @ order model. can't form field value submit add-item

so. solved problem.

i created addorderitem model announce variables

<?php namespace backend\models;  use yii\base\model;  class addorderitem extends model {    public $modelid;   public $id;   public $quantity;    public function rules() {     return [       [['modelid','id','quantity'], 'integer'],     ];   }  } 

and edited actionupdate() it's looks like

public function actionupdate($id) {     $model = $this->findmodel($id);     $addordermodel = new addorderitem();     if ($addordermodel->load(yii::$app->request->post())) {       $product = product::findone($addordermodel->id);       $orderitem = new orderitem();       $orderitem->order_id = $model->id;       $orderitem->title = $product->title;       $orderitem->price = $product->getprice();       $orderitem->product_id = $product->id;       $orderitem->quantity = $addordermodel->quantity;       $orderitem->save();       return $this->redirect(['view', 'id' => $model->id]);     }      if ($model->load(yii::$app->request->post()) && $model->save()) {       return $this->redirect(['view', 'id' => $model->id]);     } else {       return $this->render('update', [         'model' => $model,         'addordermodel' => $addordermodel       ]);     }   } 

at views/order/update added following row

<?= $this->render('_additemform', ['model' => $addordermodel]); ?> 

and _additemform contains this:

<?php  use yii\helpers\html; use yii\widgets\activeform;  $form = activeform::begin(); ?>    <td><?= $form->field( $model , 'id')->textinput()->label(false) ?></td>    <td></td>   <td></td>    <td class="text-center"><?= $form->field( $model , 'quantity')->textinput()->label(false) ?></td>    <td>     <?= html::submitbutton('<i class="mdi-action-done"></i>',[       'class' => 'btn btn-add pull-right',       'data-toggle'=>'tooltip' ,       'data-placement'=>'bottom',       'title'=>'Добавить товар',     ]) ?>   </td>  <?php activeform::end(); ?> 

i can't believe done myself. , i'm glad had no 1 help, because know more.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -