S
S
Sergey Bard2018-02-02 18:18:51
Yii
Sergey Bard, 2018-02-02 18:18:51

How to add data-attribute?

Hello everyone, I started studying yii not so long ago, the following task appeared ...
I have tables:
1) products - description of products
2) attributes - name of attributes, just name
3) attributes_products - linking table which has a column with product id, attribute and custom description text for each product attribute description is different
structure similar to opencart with attributes, the only difference is that you can add different attributes to opencart, and I need to fill in all attributes is mandatory, (these attributes can only be added and removed site admin)
so I need to make blocks dynamically formed on the add page for each attribute from the table,
should be of type label attribute name (table - attributes) and input in which there will be text (table - attributes_products), (dynamic input),
in the model I select everything like this

public function getAttributes()
    {
    foreach(Attribute::find()->all() as $one){
      if (DrugsAttribute::find()->andWhere(['attribute_id' => $one->attribute_id, 'drugs_id' => $this->drugs_id])->exists()) {
        // запись существует
        $dAone = DrugsAttribute::find()->andWhere(['attribute_id' => $one->attribute_id, 'drugs_id' => $this->drugs_id])->one();
        $arrayatt[] = array('attribute_id'=>$dAone->attribute_id, 'drugs_id'=>$dAone->drugs_id, 'text'=>$dAone->text, 'name'=>$one->name);
      } else {
        $arrayatt[] = array('attribute_id'=>$one->attribute_id, 'drugs_id'=>$this->drugs_id, 'text'=>'', 'name'=>$one->name);
      }
    }
        return $arraysa;
    }

in the view I output like this
foreach($model->attribute_array as $one){
    echo $form->field($model, 'attribute_array')->textInput(['value' => $one["text"])->label($one["name"]);
}

everything works, but how can I save the changes now?) it just occurred to me that I just need to somehow add data-attribute and IDs and then save the changes in the afterSave() model, but I can’t find how to add them anywhere, I
tried to do this
$form->field($model, 'attribute_array')->textInput(['value' => $one["text"], 'options' =>['data-drugs_id' => $one["drugs_id"]]])->label($one["name"]);

but there are no date parameters in the post request.
Please help or suggest a better option, thanks!)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question