1

Currently I have a PHP application that runs without any framework.

For several reasons I would like to rebuild that application by using the CakePHP framework. However, this application has an old database scheme that doesn't comply with Cake's practices (it's even not in English).

I would like to rebuild this application piece by piece and continue using the old one for the parts that haven't migrated yet, so I cannot make any real schema changes.

Is it possible to create some sort of route of proxy between new scheme and old scheme? So that is't possible in Cake to work like I want to (e.g. field 'user_name' in Model "User") but on the background still use old database scheme (e.g. 'naam' in table 'gebruikers').

Wouter
  • 49
  • 1
  • 6
  • The answer probably depends on: What are examples of the statement: _old database scheme that doesn't comply with Cake's practices_? Do the tables have a primary key of auto_increment or UUID? – AgRizzo Mar 17 '15 at 11:33
  • Yes, it has a auto_increment. But for example current table called "gebruikers" (= Dutch for users) and a column might be "naam" (= name). I don't want to start using "findGebruikerByNaam" now, because I would like to rename everything in the end so I would like to start programming now with "findUserByName" – Wouter Mar 17 '15 at 18:04
  • 1
    Here's one technique: Put a MySQL view in front of a table. For instance, create a view called "users" and rename the column "naam" to "name" in the view. This combined with answer by Catalin should give you a starting point to the rebuild. – AgRizzo Mar 17 '15 at 18:13

1 Answers1

0

There is no proxy in CakePHP 2.X for the Model behavior that you desire.

Still you could build your app by following the most important CakePHP conventions by adding some Model settings:

  • you can specify the table used by each Model with $useTable property (docs)
  • you can specify the primaryKey if it's not equal to id (docs)
  • you can use a custom foreignKey to set the relationship between two models (check this answer here which contains a nice explanation)

This should get you started and leave the table field name changes for later.

Official docs for Model Attributes and Associations

Community
  • 1
  • 1
Catalin MUNTEANU
  • 5,618
  • 2
  • 35
  • 43