Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic theme switching seems do not work #208

Open
fazliddin opened this issue Dec 26, 2024 · 3 comments
Open

Dynamic theme switching seems do not work #208

fazliddin opened this issue Dec 26, 2024 · 3 comments

Comments

@fazliddin
Copy link

fazliddin commented Dec 26, 2024

project/src/framework/controllers/BaseAdminController.php

namespace app\framework\controllers;

use yii\base\Theme;
use yii\web\Controller;

abstract class BaseAdminController extends Controller
{
    public function init()
    {
        parent::init();

        \Yii::$app->getView()->theme = new Theme([
            'basePath' => '@themes/admin',
            'baseUrl' => '@web/themes/admin',
            'pathMap' => [
                '@app/views' => '@themes/admin',
            ],
        ]);

        //print_r(\Yii::$app->getView()->theme);
        //die("hello");

    }
}

project/src/modules/site/controllers/AdminSiteController.php

namespace app\modules\site\controllers;

use app\framework\controllers\BaseAdminController;
use yii\filters\AccessControl;

class AdminSiteController extends BaseAdminController
{
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::class,
                'only' => ['logout', 'signup'],
                'rules' => [
                    [
                        'actions' => ['signup'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
        ];
    }

    public function actions()
    {
        return [
            'error' => [
                'class' => \yii\web\ErrorAction::class,
            ],
        ];
    }
}

config.php

'errorHandler' => [
    'errorAction' => 'site/admin-site/error',
],

Error

An Error occurred while handling another error:
yii\base\ViewNotFoundException: The view file does not exist: /var/www/vhosts/ulkanv2/ulkansayt/template/src/modules/site/views/admin-site/error.php in /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/View.php:234
Stack trace:
#0 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/View.php(157): yii\base\View->renderFile()
#1 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/Controller.php(407): yii\base\View->render()
#2 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/web/ErrorAction.php(139): yii\base\Controller->render()
#3 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/web/ErrorAction.php(118): yii\web\ErrorAction->renderHtmlResponse()
#4 [internal function]: yii\web\ErrorAction->run()
#5 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/Action.php(93): call_user_func_array()
#6 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\Action->runWithParams()
#7 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#8 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/web/ErrorHandler.php(109): yii\base\Module->runAction()
#9 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/ErrorHandler.php(152): yii\web\ErrorHandler->renderException()
#10 [internal function]: yii\base\ErrorHandler->handleException()
#11 {main}
Previous exception:
yii\base\InvalidRouteException: Unable to resolve the request "admin/index.php". in /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/Module.php:561
Stack trace:
#0 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction()
#1 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest()
#2 /var/www/vhosts/ulkanv2/ulkansayt/template/public/index.php(19): yii\base\Application->run()
#3 {main}

Next yii\web\NotFoundHttpException: Page not found. in /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/web/Application.php:115
Stack trace:
#0 /var/www/vhosts/ulkanv2/ulkansayt/template/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest()
#1 /var/www/vhosts/ulkanv2/ulkansayt/template/public/index.php(19): yii\base\Application->run()
#2 {main}

In this project we do not want default view folders like @app/views. We want all view files in theme folder, because we have many themes for one site.

@samdark
Copy link
Owner

samdark commented Dec 26, 2024

Including errors?

@fazliddin
Copy link
Author

Yes
Do you mean error view file should be in @app/views? That is, themes must not have error.php?

@samdark
Copy link
Owner

samdark commented Dec 26, 2024

Try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants