Adding new app to Advanced Template

Time to add another app, let’s call it “frontEnd2” to the advanced template.

I’ve copied the existing /frontend folder (to /frontend2) and have done a search (“frontend/”) and replace (“frontend2/”) within the copied folder to change all “namespace” and “use” commands to use the new namespace.

The index.php bootstrap was changed so that the proper /frontend2 config and bootstrap files are being loaded.

All I get is a yii\base\InvalidRouteException error in C:\inetpub\htdocsPortals2\vendor\yiisoft\yii2\base\Module.php:461.

What did I miss? Is there something else with the frontend2 namespace I need to do to make it available (assuming that is the issue).

Thanks in advance.

Hi Rick,

Is there a specific reason for creating a new folder in application root folder? If so, could you explain it?

Yes the reason you might have multiple application that uses common files. For me I have used improved advance template created by nenad see GIt Git link and adding a new folder for a different application is as simple as a drop. And also for a shared hosting I dont have to go through all the tutorials in yii2 installation.

Bonnie hit the nail on the head. I maintain quite a few projects that mostly have the same base features. With Yii, I had rearranged the structure so that all my common files, components, models, modules, etc could be shared by each app. My development environment had all the different apps, and all I had to do was push the specific app and the common directory to the production server. It worked really well for us.

Bonnie, thanks, I will take a look at the improved advanced template. It looks like it has more than I need, so maybe I can figure out how they were able to add new apps.

OK, here is the solution for anyone else who runs into this –

The classes in the new folder frontend2 were not being autoloaded. After a much more detailed reading of the Yii2 guide, you simply need to add a root alias for the frontend2 directory for Yii’s autoloader to load them.

In my case, I added the following to /frontend2/config/main.php

  'aliases' => [

      '@frontend2' => '@common/../frontend2', 


Awesome, thanks!