yii3 如何像yii2 advanced demo一样前端和后台一起开发?

Author: Anonymous Publish Time : 2023.11.23 02:36:09 Updated Time : 2023.11.23 02:36:09

没错,虽然Yii3过了好几年还没有开发出来,我们已经早早的上车了,哈哈,演示程序

https://www.tianex.com

由于我们是最先上车的,开发过程中也是有点小技巧,按照下面的方法可以把几个apps在一起开发,这样可以加快开发速度,部署的时候可以按照需要分开独立部署,(我不清除部署在一起会不会比较耗资源)

 

if you want to  develop multiple yii3 apps in the same folder,just like yii2 advance demo

we have a solution

the idea is filter the url accessed  to the different app(instance) and load different config files

1. move the yii3 demo config files to a subfolder of config ,maybe frontend

if you want to add backend just copy frontend files to backend

if you need the app frontend and backend ,the config should includ 2 subfolders 

config/frontend, config/backend

and modify the .merge-plan.php file in each app config folder

from  

return [
    '/' => [

to 

return [
    '/frontend (or othe app name)' => [

make sure it can load the right vender libs

 

2.modify the public/index.php to forward access to the different apps,

such as https://www.tianexcom/backend to load config/backend config files,

$request_uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

$_ENV['YII_ENV'] = '/frontend';
 
if (!empty($request_uri)) {
    if (str_starts_with($request_uri, '/backend')) {
        $_ENV['YII_ENV'] = '/backend';

}

 

to do this, you also need to mody the 

vendor\yiisoft\yii-runner\src\ApplicationRunner.php
 protected function createDefaultConfig(): Config
    {
        return ConfigFactory::create(new ConfigPaths($this->rootPath, 'config'.$this->environment), $this->environment);
    }

 

 

Comment
Login To Comment

No Comments