开发者_如何学PythonWhat are the restrictions on table names and database design with CakePHP
i have a database already working another app.
I want to build a new interface with CakePHP
will i need to redesign the database
You don't have to follow the naming conventions for the database with Cake. It makes things a lot easier and keeps things very organized and structured. However, any framework that forces you to follow ITS patterns should through red flags. At least it does for me.
That being said, the conventions are simple. Here are a few of the basics:
- Table names are pluralized (ie. users, computers, songs, teachers, children, etc.)
- Primary keys should be labeled as id
- The name field will be read automatically for display
- Foreign keys contain the singular name of the table _id (ie. user_id, computer_id, song_id, etc.)
http://book.cakephp.org/view/68/Creating-Database-Tables
These are just the basics. Now they may not apply to every application. Especially if you already have existing tables you want to use. It doesn't make sense to convert the structure of the database to have to fit in with Cake. So there are variables you can use in the model to tell cake the name of the tables and fields you are using.
To change the table name a model points to: var $useTable = 'myTable';
To tell cake what the display field is: var $displayField = 'somefield';
To tell cake what field to use as the PK: var $primaryKey = 'some_id';
http://book.cakephp.org/view/71/Model-Attributes
This should be enough to get you going. Good luck!
Model and Database Conventions in CakePHP
http://book.cakephp.org/view/903/Model-and-Database-Conventions
精彩评论