Now that Flextrine has been configured we need to create our entities. Entities are the objects that we want to enable for reading and writing to the database, and they are defined in PHP in the entities directory of the Flextrine server side component.
The requirements for our simple address book are that we need to have groups containing contacts. Unfortunately Group is a reserved word in SQL so we’ll call it ContactGroup. ContactGroups have a name, and many Contacts, and Contacts have a name, telephone number, birthday and a contactGroup. We are going to place all our entities in the vo package. This gives us the class diagram below:
Create a folder called vo in the entities directory of the Flextrine server side component and create ContactGroup.php and Contact.php with the contents given below. More information on writing entities can be found in the Doctrine documentation for Basic Mapping and Association Mapping. The main thing to remember when creating entities is that:
- All mapped attributes must be public
Now that we have created our entity definitions we need to create the matching database schema.