R
R
Rafail Dunyashev2016-11-25 10:12:41
Yii
Rafail Dunyashev, 2016-11-25 10:12:41

Why doesn't appendTimestamp work for several AssetBundles, but it works for the rest?

Everything is written in the web.php file:

$config = [
....
  'components' => [
    'assetManager' => [
      'appendTimestamp' => true
    ],

If a file, for example, admin.js is included here, then appendTimestamp does not work:
<?php
namespace app\assets;

use yii\web\AssetBundle;

class AdminAsset extends AssetBundle
{
  public $css = [
    'css/admin.css',
    	'css/icons.css',
  ];
  public $js = [
    'js/admin.js'
  ];
public $depends = [
    '\yii\web\YiiAsset',
    '\app\assets\BootstrapSwitchAsset',
    '\app\assets\TizixBootstrapAsset',
    '\app\assets\JqueryUIAsset',
    '\app\assets\TinyMceAsset',
        '\app\widget\uploader\assets\UploaderAssets',
  ];

and if in AppAsset, then everything works:
<?php
namespace app\assets;

use yii\web\AssetBundle;

class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $js = [
    'js/admin.js',
    ];
    public $depends = [
        '\yii\web\YiiAsset'
    ];

I can't figure out what's the catch?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
M
Maxim Fedorov, 2016-11-25
@NoizeMC

Since the basePath and baseUrl properties are not set in AdminAsset, they are picked up from the corresponding properties of the resource manager. And in the resource manager, they are set to @webroot/assets and @web/assets respectively. You have the admin.js file in the @webroot/js/admin.js directory, and due to the unset properties of the resource kit, the manager looks for it along the path @webroot/assets/js/admin.js, which is why there are problems with AdminAsset. With AppAsset, such problems are not observed. You set the correct paths to the files in it

R
Rafail Dunyashev, 2016-11-25
@NoizeMC

The problem was solved by adding:

public $basePath = '@webroot';
public $baseUrl = '@web';

in AdminAsset
But why didn't it work without it?

A
Alexander Borisovich, 2018-01-13
@Alexufo

Keep in mind the walkers - the paths must be without the first slash
, that is, this will work

public $js = [
    'js/admin.js',
    ];

And so, but there will be no time stamp.
public $js = [
    '/js/admin.js',
    ];

I had to connect the Indian until I realized why it didn’t work.

I
Ivan Bogachev, 2017-03-12
@N_Grevtsov

Hmm....

A
Anna, 2017-03-15
@Desperate_ua

in Photoshop, this frame can be made, then substitute the text and the button

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question