我想在 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,.. )但不起作用。