Skip to content
Ryan Fischbach edited this page Sep 17, 2015 · 3 revisions

Models all share a common ancestry and a single Model class can only talk to one db connection as standard practice. However, there is a built-in mechanism to change what connection to use.

Using different connection credentials

In order to use a db connection that is different from the one where the "webapp" is being used, create your inherited Model class and then change the const dbConnName = 'webapp'; to some other name, e.g. 'bob'. In your config folder (app/config/localhost for a localhost dev machine), copy the dbconn-webapp.ini file and name the copy as dbconn-bob.ini. Open that file up and change the credentials to what you need for the alternate db connection. Once you save the file, your model class will automatically connect using the credentials stored in dbconn-bob.ini and the Director class will automatically handle keeping track of the connection and sharing with any other Model class that may require it. Look in the app\DbConnInfo class for additional properties and methods you have access to via the Model::myDbConnInfo property.

Framework Database Schema

The framework cannot exist without a minimal set of database tables. The diagram displays the tables the website will use.

Updating Existing Model Schema

  1. add the IFeatureVersioning interface if the model does not yet implement it.
  2. add the field to the create table definition (traditionally the getTableDefSql() method).
  3. add 1 to the FEATURE_VERSION_SEQ class constant.
  4. update determineExistingFeatureVersion() so that the older FEATURE_VERSION_SEQ number can be discovered by existing schema (usually an if !isFieldExists() call)
  5. add to the switch statement in upgradeFeatureVersion() so that it will alter the existing table and add your new field (or whatever needs to be done).
  6. test the above code by creating a new website with a new database to test “new website” and then upload the new PHP code to an existing website to test the update schema code (don’t forget to save off the existing database so you can easily recover when things go wrong)

Clone this wiki locally