Hello,

I would like to get an advice on how to build an application with
CakePHP where there are multiple customers (companies) using the
application and each have their own database, but also some common
tables in another database. Let me explain the database structure:

Tables in common database:

- Users
- Companies
- Common settings
- ...

Tables in company specific database:

- Users extra profile data
- Company employees
- ...

So all users register to the application and the basic information is
stored in a table in the common database. The application lists
companies that are available. When users goes to some specific company
page for the first time, they need to add extra profile data that the
company wants. This data is stored to the company database.

So I have couple questions.

1. Can I link tables between database configs?

E.g. if you look at the tables above, the users extra profile data
table in company database have user_id foreign key what is the ID of
the user in Users table in common database. Same goes for the company
employees table. It has a user_id foreign key, all employees are just
some users with extra fields in that table and employee id.

2. How to automate the database table selection?

I briefly checked this article: 
http://recurser.com/articles/2007/06/04/multiple-dbs-in-cakephp/

That seems to work for me also to some extent. I can adapt that
information and then have two database configurations in app/config/
database.php. One config for the common database that never changes
and then another config what uses the system from the above article to
make the database selection. Does someone have better idea?

But the more important question for the database table selection is
that how to know what database to select. The article selects the
database via user info, but in my application, users are not tied to
some specific database. I was going to do it with subdomains. The
application would check what subdomain is used and then find the
database for that subdomain. It would work all ok, but I need to build
an installation system to the application what can be used to add
companies easily online. So I'd need to make it add the subdomain also
and vhost to apache and restart apache. I don't like the idea of
having to restart apache every time a company is added. So I'd like to
use the first part of the url instead. There would be urls like this:

www.domain.com/company1/home
www.domain.com/company2/home
....

So what I'm thinking (without knowing CakePHP capabilities) is to hack
app/webroot/index.php and take the company part out from the $url and
store it to session and read it from there when it's time to select
the database. That way the application would select the correct
database based on the url. But it requires modifications to the app/
webroot/index.php and there might be a better way to do this. So is
there? :)

Could I for example extend the CakePHP dispatcher what would take the
first part from the url out and store it somewhere and then use the
rest of the url normally to navigate to the controller etc? or...?

Thanks in advance if you took the time to read all this :) Sorry for
the lengthy post.

Oh and environment is:

Apache HTTPD 2.2.11
MySQL 5.1.33
PHP 5.2.9
CakePHP 1.2.3.8166

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to