Hello. Tell me why we need themes and when is it better to use them? Why not just use the view to separate the static parts of the page (header, footer)? I do not get you...

And also, is it possible to ask several topics? Suppose for the site itself, and then for the admin panel? How is the theme change implemented?

    2 answers 2

    Tell me why we need themes and when is it better to use them?

    For the same, for what and in WordPress: to provide the possibility of different designs of the same application without the need to rewrite files. Also, themes can be used to implement template inheritance: when defining templates in the default application folder, you can override them with templates in the themes folder, and thus display the changed view in the default layout and vice versa.

    Why not just use the view to separate the static parts of the page (header, footer)?

    Because in Yii, the choice was made in favor of the general template (layout) and widgets. Arbitrary places in the template still come up against the need for widgets, and the static parts simply become unnecessary burdens - they are easier to arrange as widgets and don’t waste time supporting an unnecessary entity. Not to mention the fact that in a serious application there are always some promotional pages where everything is turned upside down, and here it is easier to write a separate layout. Well, no one bothers to connect individual files in the layout.

    And also, is it possible to ask several topics?

    At the same time - no, to set an arbitrary topic when requesting - please:

    Yii::app()->theme = 'default'; // используется тема default. 

    But, in general, this does not make much sense, this functionality is extremely rarely required.

    Suppose for the site itself, and then for the admin panel?

    It is possible, but I would not do that. You need to set the subject either in the config or in runtime, and this may just be superfluous information. On the other hand, if you have different configs for the admin and frontend, then why not unleash the visual presentation.

    • Yii :: app () -> theme-> name = 'default'; Checked? How does that work? I knew only Yii :: app () -> setTheme ('default'); - dekameron
    • @dekameron, I lied, of course, I will correct it now - etki

    You can ask as many topics as you like. When using a theme, you must specify it in the config:

     return array( 'name' => 'SiteName', 'theme' => 'themeDirectory' //Чувствительна к регистру в Unix-based системах //... ); 

    You can use it at your own discretion, and as much as you like (for example, allow authorized users to choose a topic themselves, and unauthorized to write it in cookies)

    Here is a small topic guide.