A
A
asferot2018-11-27 15:33:02
Yii
asferot, 2018-11-27 15:33:02

How to get rid of enumeration of strings in an array?

How to get rid of enumeration of strings in an array?
5bfd38ef2a4e8795684416.png
The screenshot shows 0 and 1 in the list. How can you get rid of this?
Controller:

$ships = Ship_company::find()->select('name')->all();

View:
<?php foreach($ships as $ship): ?>
          <?php $items[]= [$ship->name => $ship->name];?>
      <?php endforeach; ?>
 <?= $form->field($post, 'Who_ship')->dropDownList($items, ['promt' => 'Select']); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-11-27
@asferot

Good afternoon.
And it would be more correct, I think, like this:
in the Ship_company model

public static function getNamges()
{
    return ArrayHelper::map( self::find()->select(['name', 'id'])->all(), 'id', 'name');
}

as
$form->field($post, 'Who_ship')->dropDownList(Ship_company::getNames(), ['promt' => 'Select']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question