3

I try to create lib for editing pictures. I have main js file for including all other js, css and images files. For example, I used:

$.getScript(site_url + '/vendor/first_folder/second_folder/assets/js/script.js');

I read that path for web sets at AppAsset.php, if I will ask change @webroot to @vendor.. at extention configuration I think it will be wrong. I created my MyAsset.php and set there such configurations:

namespace app\vendor\first_folder\second_folder;

use yii\web\AssetBundle;

class EdikEditorAsset extends AssetBundle {

    public $sourcePath = '@vendor/first_folder/second_folder/assets/';
    public $css = [
         'css/main.css'
    ];
    public $js = [      
        'js/jquery.colorbox-min.js',      
        'js/main.js'        
    ];   
}

But I cannot include others js, css and image files from my extention, because all js,css and images start including from web folder and I don't know how go do above. What can I change for including js, css, images files from vendor folder?

P.S. I tried to change using different paths this part in js, but noone worked, so I think problem not in this:

$.getScript(site_url + '/vendor/first_folder/second_folder/assets/js/script.js);

3
  • is the vendor folder accessible on web? Commented Apr 1, 2015 at 15:48
  • No, vendor is in a site folder. Commented Apr 2, 2015 at 17:32
  • All files that you want to be accessible to client should be in web accessible directory. If they are not client would never access them. Commented May 28, 2015 at 13:37

1 Answer 1

3

Vendor folder is not web accessible. One solution is to symlink the css, js, img from vendor folder into the web folder. Then include that. Or here is the Yii way to do it:

<?php

namespace app\assets;

use yii\web\AssetBundle;

class BootstrapAsset extends AssetBundle {

//set the source path using @vendor or another alias like @bower here
  public $sourcePath = '@bower/bootstrap/dist';

//include css and js relative to the source path set above
  public $css = [
    'css/bootstrap.css',
  ];
  public $js = [
    'js/bootstrap.min.js',
  ];
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.