What I need to accomplish is a single Application with a single database but multiple accounts (companies), each with multiple users.
The URL convention must be as follows: domain.com/account/controller/action
So ALL controllers are prefixed by the company/account name.
All accounts would share the single database, but each one would need to be able to restrict access to their data.
The question is, how do I implement this? I’ve thought about implementing some sort of htaccess rewrite where I strip out the first URL parameter (account) and pass as a query string parameter, which would be internally parsed by the app_controller. The challenge, however, is maintaining integrity with all of the links throughout the app. I.e. the cake routing would somehow need to be aware of the account parameter and pass it to all outputted links.
Has anyone accomplished something similar to this before?
You can do two things, both with Routes.
First, setting a variable in the routes:
And now you can access the user variable with
$this->params['user']. The thing with this is that you will have to manually set each controller and action you want to manage. I think it’s no big deal, since most of the times it is better to rewrite the default routes architecture for CakePHP.Second, you can tell you are waiting for a variable and will be accessible as a parameter in your function.
In your controller:
And now you will be getting both vars.
I don’t know if it can be made automatically, perhaps rewriting the htaccess could be a good idea.
Hope it helped.