gpt4 book ai didi

php - 在 Controller 中覆盖 Yii2 assetManager 配置

转载 作者:搜寻专家 更新时间:2023-10-31 20:38:56 25 4
gpt4 key购买 nike

我使用 yii-jui 在 View 中添加一些 UI 元素,例如 datePicker。在 frontend\config\main-local.php 中,我设置了以下内容以更改 JqueryUI 使用的主题:

$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'gjhgjhghjg87hjh8878878',
],
'assetManager' => [
'bundles' => [
'yii\jui\JuiAsset' => [
'css' =>
['themes/flick/jquery-ui.css'],
],
],
],
],
];

我尝试了以下方法来覆盖 Controller 操作方法中的这个配置项:

public function actions() {  

Yii::$app->components['assetManager'] = [
'bundles' => [
'yii\jui\JuiAsset' => [
'css' =>
['themes/dot-luv/jquery-ui.css'],
],
],
];
return parent::actions();
}

我还尝试将上面显示的 Yii::$app->components['assetManager'] 的值设置为 View 本身(它是部分 View 表单 _form.php) 和调用此 View (updateAction) 的操作。然而,所有这些尝试都没有成功改变主题。 Yii2 中是否有类似 CakePHP 中的方法,例如 Configure::write($key, $value);

最佳答案

你应该修改 Yii::$app->assetManager->bundles(Yii::$app->assetManager 是一个对象,而不是数组),例如

Yii::$app->assetManager->bundles = [
'yii\jui\JuiAsset' => [
'css' => ['themes/dot-luv/jquery-ui.css'],
],
];

或者如果你想保留其他包配置:

Yii::$app->assetManager->bundles['yii\jui\JuiAsset'] = [
'css' => ['themes/dot-luv/jquery-ui.css'],
];

关于php - 在 Controller 中覆盖 Yii2 assetManager 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28110404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com