小编OcB*_*974的帖子

如何以 symfony 形式选择显示很棒的字体图标

我想在 Symfony Form Builder 的选择选项中显示所有字体很棒的图标。

我添加选择字段:

$choices = $this->getFontAwesome();
$form->add( $key, ChoiceType::class, array('label' => 'Texte', 'choices' => $choices, 'attr' => array('class' => "fa" ) ) );
Run Code Online (Sandbox Code Playgroud)

我的函数 getFontAwesome();

    public function getFontAwesome(){

    $webroot = $this->get('kernel')->getRootDir() . '/../web';
    $pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s+{\s*content:\s*"\\\\(.+)";\s+}/';
    $subject =  file_get_contents( $webroot . '/assets/vendor/font-awesome/css/font-awesome.css');
    preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER);
    foreach($matches as $match) {
        $icons[$match[1]] = '&#x' . $match[2] . ';' ;
    }

    return $icons ;

}
Run Code Online (Sandbox Code Playgroud)

但在选择字段中,看不到该图标:

字段显示代码而不是图标

在此输入图像描述

我该怎么办?我尝试 htmlspecialschars 和其他( htmlentities,.. )但不起作用。

php forms symfony font-awesome

5
推荐指数
1
解决办法
4698
查看次数

标签 统计

font-awesome ×1

forms ×1

php ×1

symfony ×1