Imagine you’re building an e-commerce platform where you develop numerous application components. Some of them belong to the backend, some to the frontend and some are shared between the applications.
If you were to build a shopping cart component, you would only need it in the frontend and then you might have some components you only need in the backend. It would be great if both parts of your platform could be configured together (common config) and separately (frontend and backend configs in respective apps).
Also, most of the models you want to share directly between the apps so generating them with Gii once under common/models saves you a huge amount of time because you only need to maintain a single model instead of two different models, which you would need to if you built the backend with a different framework, e.g. django.
I love Yii because it’s a rapid application development framework which means that I can develop complicated apps quickly compared to most of the other frameworks out there. It would be superb if I could build both my frontend and backend in the same manner taking benefit of all the great features in Yii.
I have quite some experience in creating backend modules and I can tell you that it’s not the way to go if you’re building a large scale application. While it might seems like an easy solution it doesn’t allow you to separate your backend and frontend code-base well enough, at least not in my opinion.
Mike’s idea about having a component which creates another application seems a bit overkill, but it would of course also be an alternative solution.
I’d still like to explore the alternative of creating a custom URL manager to handle the routing. Wouldn’t it be possible to have both shared rules and app-specific rules? What I mean is that we could build an URL manager for which you could configure both shared and app specific URL configurations.
Here’s an example config so that you get a better picture of what I’m talking about:
'urlManager'=>array(
'class'=>'UrlManager',
'urlFormat'=>'path',
'rules'=>array( // shared rules
......,
),
'apps'=>array(
'frontend'=>array( // frontend config
'cacheID'=>'dbCache',
'showScriptName'=>false,
'urlRuleClass'=>'UrlRule',
'rules'=>array(
.....
),
),
'backend'=>array( // backend config
'cacheID'=>'cache',
'rules'=>array(
.....
),
),
),
),
In order words instead of specifying a URL manager component in both applications it could be done in the common config where both applications can be configured both together and separately.
Couldn’t this be working solution or is it too much of a hack as well?