简体   繁体   中英

Yii2 How to reference the public main.php file on the server

I used yii2 framework to do three sites, the three sites belonging to different servers, their layouts / main.php exactly the same, how to make these three different domain name website share this main.php?For example, a company's community and forums, as well as the official website are exactly the same layout file, which means that the three sites of the header and footer is the same, according to my current practice, the three sites are writing this layout File and inside the style and pictures, then the problem occurs, if you want to change the footer and the title html, css, js or pictures, there will be three sites together, this is too much trouble. My current idea is to put the main.php file into one of the site's root directory, and then three sites in the frontend / layouts / main.php reference to the main.php inside the code, but how to do pictures and Style, please Experts advise?

You can include remote files using the allow_url_include directive, but this is a really bad idea because of the security risks.

In my opinion the way to go is to build a module with your layout-related files and then update it in the applications, using composer (or any other tool) when you make changes.

You could use a scaffolding like advanced template where different application (eg: backend and frontend) share common code .. Yii 2 Advanced Project Template is a skeleton Yii 2 application best for developing complex Web applications with multiple tiers.

By default the advanced template includes three tiers: front end, back end, and console, each of which is a separate Yii application. front end and back end app share common namespace for models and config and you can extend for place a common layout or other application based on the same guidelines

This template is also designed to work in a team development environment. It supports deploying the application in different environments.

https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/README.md

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM