gpt4 book ai didi

yii2 - 如何将参数传递给 mainLayoutAsset.php 文件?

转载 作者:行者123 更新时间:2023-12-04 18:03:20 27 4
gpt4 key购买 nike

我在 mainLayoutAsset.php 文件中有以下代码

<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace frontend\assets;
use yii\web\AssetBundle;

/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class MainLayoutAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'member-area/AdminLTE/app.js',
];
}

现在我想访问这个文件中的 params 文件参数

例如。
public $js = [
'member-area/AdminLTE/app.js?v='.Yii::$app->params["version"],
]

但它给出了错误
PHP Parse Error – yii\base\ErrorException
syntax error, unexpected '.', expecting ']'

'js/tooltip.js?v='.Yii::$app->params["incFileVersion"],

最佳答案

来自关于类属性的 PHP 文档:

They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.



http://php.net/manual/en/language.oop5.properties.php

您可以简单地覆盖 init() :
public function init()
{
parent::init();
$this->js = [
'member-area/AdminLTE/app.js?v=' . Yii::$app->params['version'],
];
}

你应该是 try this反而。

关于yii2 - 如何将参数传递给 mainLayoutAsset.php 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37991346/

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