I have following code in mainLayoutAsset.php file
<?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 <[email protected]>
* @since 2.0
*/
class MainLayoutAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'member-area/AdminLTE/app.js',
];
}
Now I want to access params file parameter in to this file
eg.
public $js = [
'member-area/AdminLTE/app.js?v='.Yii::$app->params["version"],
]
but it giving error
PHP Parse Error – yii\base\ErrorException
syntax error, unexpected '.', expecting ']'
'js/tooltip.js?v='.Yii::$app->params["incFileVersion"],
From PHP documentation about class properties :
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
You could simply override init()
:
public function init()
{
parent::init();
$this->js = [
'member-area/AdminLTE/app.js?v=' . Yii::$app->params['version'],
];
}
And you should may be try this instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With