yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.91k forks source link

Yii 2: theming problem #17298

Open hyquoccuong opened 5 years ago

hyquoccuong commented 5 years ago

What steps will reproduce the problem?

I'm using theme for frontend application

I want to keep view files and modules in theme folder and follow this tutorial https://www.yiiframework.com/doc/guide/2.0/en/output-theming

My theme folder is /frontend/web/themes/mytheme

If I create

/mytheme/site/index.php

and use pathMap '@frontend/views' => '@frontend/web/themes/mytheme',

when I call site/index it render the view properly and theme asset files loaded (js and css)

But if I create folder views in mytheme folder and move site folder to inside

/mytheme/views/site/index.php

and use pathMap '@frontend/views' => '@frontend/web/themes/mytheme/views',, when I call site/index it render /mytheme/views/site/index.php view but theme assets files is not loaded, just some yii assets loaded properly

And this is my theme configuration part in for this theme in frontend/config/main.php:

'view' => [
            'theme' => [
                'baseUrl' => '@frontend/web/themes/mytheme,
                'basePath' => '@frontend/web/themes/mytheme,
                'pathMap' => [
                    //'@frontend/views' => '@frontend/web/themes/mytheme', 
                    '@frontend/views' => '@frontend/web/themes/mytheme/views',
                    '@frontend/modules' => '@frontend/web/themes/mytheme/modules',
                    '@frontend/components/widgets' => '@frontend/web/themes/mytheme/components/widgets',
                ],
            ],
        ],

What is the expected result?

Themes assets loaded

What do you get instead?

Themes assets missing

Additional info

Q A
Yii version 2.0.14
PHP version 7.1
Operating system Windows 10
yii-bot commented 5 years ago

Thank you for your question. In order for this issue tracker to be effective, it should only contain bug reports and feature requests.

We advise you to use our community driven resources:

If you are confident that there is a bug in the framework, feel free to provide information on how to reproduce it. This issue will be closed for now.

This is an automated comment, triggered by adding the label question.

neoacevedo commented 4 years ago

I'm going to re-open the issue.

I was testing this issue, and I can reproduce it.

To have the theme assets inside @frontend/web/themes/myTheme/ I have to set the $basePath and the $baseUrl parameters set into the frontend\assets\AppAsset.php class

samdark commented 4 years ago

@neoacevedo do you have a solution?

neoacevedo commented 4 years ago

Manual debugging shows me that $basePath and $baseUrl properties from yii\base\Theme are not being filled with the configuration set in

...
    view' => [
            'theme' => [
                'basePath' => '@app/themes/basic',
                'baseUrl' => '@web/themes/basic',
                'pathMap' => [
                    '@app/views' => '@app/themes/basic',
                ],
            ],
        ],

Both properties should have @app/themes/basic and @web/themes/basic or its translated aliases, but instead of it, I am getting null values. I have to use an own Theme class, setting it into the theme array config, or set both properties in the frontend/backend (advanced application) AppAsset class.

samdark commented 4 years ago

Any idea about the reason?

neoacevedo commented 4 years ago

I can't track about the null values, but I'd use className inside theme array. I will try to debug again to get a clue about the issue.