Bootswatch Theme switcher

i assume that everyone knows bootswatch.com, i like to have a theme selector that lets users select the current theme. a nice example of such an theme switcher in actions is https://patrikx3.com/en/front/about-me where he added all bootswatch themes to a pull-down menu.

lets assume that i have converted all these bootstrap themes to working yii2 themes and that they live in my themes folder. how to implement such a user selector pull-down menu? i am completely new to Yii2, could someone breakdown the step on how this could be done? (how to create the pull-down menu, i probably will manage, my question is mostly about how to configure the app instance to register all themes and allow to easily switch between them.)

Hi,

I provide a Yii2 app template at:

which uses the raoul2000/yii2-bootswatch-asset extention.

Feel free to look at assets/AppAsset.php about how this is implemented.

Other relevant files:

  • config/params-local.php.sample: Default theme
  • views/layouts/main.php: Show menu item to switch a theme

Hope this helps.

Regards

Joachim

Thanks, for your project template. Im working on creating my first stable template that i can use for my yii projects, and your template is kind of a more complex version of what i was planning to make. This would be a good starting point for me. So I like to better understand you template.

For some reason i am having problems running the migrations, so i did not fully tried everything jet, but like to ask some basic questions first.

I see that the: dektrium/yii2-user and dektrium/yii2-rbac are deprecated. And that the Yii2 framework (now) has its own default RBAC (https://www.yiiframework.com/doc/guide/2.0/en/security-authorization#rbac) so then my question is can i safely switch to the yii’s default RBAC? If the default is missing some important stuff, is there an (actively) maintained (or at least not deprecated) RBAC extension you could recommend?

And Could you explain a bit about how the language switch is implemented, and what the relevant files are? It is not immediately clear to me form the views/layouts/main.php file.

And is the yii2settings used to save the selected theme choice?

Thanks…

Hello,

I just checked creating a project based on my template. All migrations run (see INSTALL.md).

I added some more steps in the INSTALL.md file to be completed after installation.

The modules dektrium/yii2-user and dektrium/yii2-rbac are abandoned, not deprecated. But they still work great and offer many features regarding users (self-) management .

dektrium/yii2-rbac is on top of the Yii RBAC. Although you can create roles, permissions, rules by code, assigning often/many users to roles is easier using dektrium/yii2-rbac.

The languages use the message files under messages. German (de) is implemented. The file messages/config.php can be used to collect translateable phrases with the yii message command.

Switching the UI language happens in the file components/LanguageSwitcher.php. The user’s selected language is then stored and read in a user cookie.

Switching the UI theme happens in views/layouts/main.php. The GET parameter theme is checked and then stored in a user cookie.

Hope this helps?!

Regards
Joachim

Ah I have read abit more about it, and after using it in you template I understand it better. and I have check all rbac on yiigits, and it seems that dektrium still is the most popular, closely followed by yii2mod. Others seem to been much less popular.

Thanks for adding the instructions and saving email. That helped a lot. I did not realize there where so many migrations to run. I followed the instructions but was still was getting migration issues. Turns out that md files are auto-opened in a markdown editor that displays double dashes as one elongated dash. And composer did not install the dektrium module. But after these 2 problems where fixed all migrations ran smoothly.

I did not really dove into the code jet, just a quick test drive. But still like to give you my first impression. (please note that this is not meant as critique.) I will definitive be using your template, but I guess its going to take some time to get familiar with everything.

Rev. History (/site/page?view=changes) only shows information about rev.1 not 2 and 3…
your bump-version script did not seem to make any changes to CHANGES.mkd. I guess this is a bug?

the pulldown menu for the App, holds dead links. and i cannot seem to find the App controller.
im not sure what it suppose to do. But the controller name seem to be controller, which is a very unfortunate name, because searching in the project for “controller” results in almost 5k hits.

When doing a DB Backup, im getting the following error:
PHP Notice – yii\base\ErrorException Undefined index: Create Table

but when clicking the firefox back button it reloads the page and list the created backup. so the the backup creation itself works but. But possibly a bug?

One the signup form and the page you see after clicking the registration link, the error messages are displayed double. But other error messages are working fine. possibly a bug?

I cant really figure out what the Lookups CRUD is for. I mean, what does it lookup? And its not clear what kind of input is expected in the “Sort Order” field on the create page.

You added “nemmo/yii2-attachments”, so i kind of thought you would have used that for the contact-form. but apparently its not used for that. So, then where did you use the attachments uploader?

Its nice that you also like to make a distinction between site admin and developer. And i see that the gii tool in the settings menu will only be there when you login as Dev. But i cant figure out how to login as Dev or how to add isDev to the rules. I tried:

new rule: isDev, app\rbac\AuthorRule
new role: dev, Developer
edit user > assign role ‘dev(Developer)’
i tried reloging in. But i don’t get the gii link in menu.

In the config folder there are normal files and .local files. I guessed that when in ‘dev’ environment it would load the .local and otherwise the normal once. But i see they are maged together in the web.php file. But the web.local.php file seem to be not merged. Could you explain what is going on there? I mean how is decided when to marge the 2 and when not.

i will dive into to code the coming week, and maybe ask you some more questions, if you don’t mind?
And thanks for your help thusfar.