如何将yii2 Html :: icon前缀设置为font-awesome' fa fa - '使用依赖注入容器?
这就是工作。
\Yii::$container->set('yii\widgets\LinkPager', ['maxButtonCount' => 5]);
但我设置Yii::$container->set('yii\bootstrap\Html\icon', ['prefix' => 'fa fa-']);
不起作用....
谢谢。
答案 0 :(得分:0)
依赖注入(DI)容器是一个知道如何操作的对象 实例化和配置对象及其所有依赖对象。
static
方法Html::icon()
的结果是一个字符串。所以你不要为此而使用DI。而是创建自己的Html
类和嵌套的icon()
,然后将其添加到bootstrap。
/web/index.php
require(__DIR__ . '/../config/bootstrap.php');
/config/bootstrap.php
Yii::$container->set('yii\bootstrap\Html', 'common\bootstrap\Html');