creocoder / yii2-taggable

The taggable behavior for the Yii framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array to string conversion

antonkomarev opened this issue · comments

@creocoder I'm not sure about best solution of this issue after last changes: #5

I'm using this behavior config:

[
    'class' => TaggableBehavior::className(),
    'tagNamesAsArray' => true,
],

In view actions everything working well. But it broke my input widget.

Array to string conversion

<?= $form->field($model, 'tagNames')->textInput() ?>

How to change behavior's config only for update/create actions in controller or in model? Or how to deal with it?

Otherwise we need always have tagNamesAsArray => false and only set it in true state when there is a need. Like this:

<?php foreach ($model->getTagNames(true) as $tag) : ?>
    <?= Html::a($tag, ['/tag/' . $tag]) ?>
<?php endforeach ?>

@a-komarev Its expected. TaggableBehavior::tagNamesAsArray property should be used only with widgets which accept ActiveRecord array attributes. For example selectize, etc.

Otherwise we need always have tagNamesAsArray => false and only set it in true state when there is a need.

Not always, there is widgets which can work with ActiveRecord array attributes. Ofcource <?= $form->field($model, 'tagNames')->textInput() ?> is not that case.