D
D
darknet372017-06-21 20:21:01
Yii
darknet37, 2017-06-21 20:21:01

How to make an array element display in html format?

There is a function like this:

public static function getStatusList()
    {
        return ["<span class='text-danger'>Активен</span>", "<span class='text-success'>Завершен</span>"];
    }

How to make an array element displayed in html format, for example in a dropDownList?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-06-21
@darknet37

Good evening.
In the model:

const STATUS_BLOCKED = 0;
    const STATUS_ACTIVE = 1;

    /**
     * @return mixed
     */
    public function getStatusName()
    {
        return ArrayHelper::getValue(self::getStatusesArray(), $this->status);
    }

    /**
     * @return array
     */
    public static function getStatusesArray()
    {
        return [
            self::STATUS_ACTIVE => 'Активен',
            self::STATUS_BLOCKED => 'Завершён'
        ];
    }

In the shape of:
In view.php file
'value' => Html::tag('span',
                                     $model->getStatusName(),
                                     ['class' => 'label label-' . ArrayHelper::getValue([0 => 'danger', 1 => 'success'], $model->status)])
            ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question