So I have my first Yii app ready in a few days from now. However, as a biz owner I see prospects of different clients wanting the same software but I do not want to have to maintain x copies of the same app for x number of clients. This will cripple my biz.
So I am trying to figure out a way to use same core for all clients and just create views only for clients. This wil be x set of views for x clients but easier that way. Problem is how do I do a directory structure so all clients share the same models and controllers. Of course, they will all run on my server much like a SaaS thing.
Thanks I had a quick look at themes on the Yii def. guide site. I think I will be able to use that for the front end of each client. I think I would also need to use a different main.php config file for each client as I would need different databases for them as well as few other configs and their own back end area.
you could use one main.php and dynamically add database component to application in beforeAction handler for example… there is no easy way to use multiple config files because to choose right one you need to initialize session and session is configured in config file (loop in dependecies)
Ok I think that method may be a lot of help, yes. However, it requires creating a beforeAction for each action in a controller if I am not mistaken, I might need to figure out a way to do this much fewer number of times so as not to create a maintenance burden? That aside, doesn’t dynamically setting the database component that frequently have any performance effects?
oh i see…will try this out and sorry it took me ages to come back here. Got occupied to the teeth on something else. Thanks though, I appreciate a lot.
ok now I have tried the themes approach. Cool experience and I used it to solve a problem. But unfortunately, it does not solve this particular one for me. But thanks @redguy on that.
I guess I asked the question wrongly earlier. What I want is that each client will have their own directory (as a subdomain on the server), each client directory will have all the yii app directories except the protected folder which will be shared by all clients. The views folder however, will be in the client directory instead of the protected folder because each client will have its own unique views and should be able to edit them.
What I have done
I have used getViewPath() in the components->Controller class to set the app viewPath for each client dynamically but the problem is with the layout files. Had to use
Yii:app()->setLayoutPath()
to set the layout path to the client views directory layout folder and
$this->layout = 'main'
to set the layout file. But then I can only use layout main but not cannot use column1 or column2 layout files. Execution gets to them quite all right (I tested with echo statements) but I cant get the main layout file rendered/wrapped from there. I am positive this is a path issue.
$this->beginContent('main');
does not seem to be finding the main.php file.
Direcroy Setup
protected - at a higher directory
Folder setup for each client directory
-assets
-css
-images
-themes
-views (views for this client only,contains contoller view folders and layouts folder)
–layouts
—column1.php
—column2.php
—main.php
–site
— index.php (and other view files for the site controller)
pls note that the protected folder will be at a higher directory level and will be referenced on the entry script. I know this is long but I had to make it clear pls read through and ask for clarification if needed. I will appreciate any help from any one. Thanks in advance