1

I have a dropdown list that gets data from a function, the function pulls a list of all files in a certain folder. However, i need to capture the value of the file name, so i need to output the array with both value and name. Here's my code;

function in model;

public static function getEmailNewUserView() {
        $files = CFileHelper::findFiles(Yii::getPathOfAlias('webroot.themes.'.Yii::app()->name.'.views.mail'), array('absolutePaths'=>false));
        return $files;
    }

HTML element in _form

<?php echo $form->dropDownListGroup(
        $model,
        'email_newuser_view',
        array(
            'wrapperHtmlOptions' => array(
                'class' => 'col-md-6',
            ),
            'widgetOptions' => array(
                'data' => Options::model()->getEmailNewUserView(),
            )
        )
    ); ?>

This outputs;

<option value="0">item</option>

I need it it output

<option value="item">item</option>

Anyone know how to do this in Yii?

1 Answer 1

2

You can use array_combine

public static function getEmailNewUserView() {
    $files = CFileHelper::findFiles(Yii::getPathOfAlias('webroot.themes.'.Yii::app()->name.'.views.mail'), array('absolutePaths'=>false));
    return array_combine($files, $files);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Edofre, exactly what i was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.