0

I've follow this video tutorial to enable pretty URL.

https://www.youtube.com/watch?v=suIx8nyDBKk

Everything works fine, until I use custom css.

If I'm at homepage, css link is abc.com/css/main.css. But when i go to another page, ex: post/index, the link change to abc.com/post/css/main.css. So there is no css there, the page is broken.

Please help me how to solve this problem.

Thank you.

1 Answer 1

1

You have to use AppAsset to define your css and js files. Also this is related to not using a "/" before the css url, because you not getting a root directory. If you define a css in layout file and not set to be like "/css/main.css", then every time it will break the style while your go out of your root directory. Here is the example:

/**
 * @author Qiang Xue <[email protected]>
 * @since 2.0
 */
class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';
    public $css = [
        'css/main.css',
    ];
    public $js = [
    ];
    public $depends = [
        'yii\web\YiiAsset',
        'yii\bootstrap\BootstrapAsset',
    ];
}
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.