Flextrine 0.6.5 released

Another released of Flextrine!  Since 0.6.1 there have been a number of changes to the Flextrine core.  The entity merging algorithm has been altered to take better advantage of Doctrine 2 merging giving us a hefty performance boost (thanks for Benjamin Eberlei at Doctrine for pointing this out), the requirement to use $_explicitType in Doctrine entities has now been removed, bootstrapping and configuration code has been extended and neatened up and there have been numerous bug fixes at all levels of the application.

My continued thanks to the community for their help in testing and using Flextrine!

Flextrine Tutorial – CRUD in a simple Flex 4 address book: Creating the entities

Introduction
Setting up the server
Creating the entities
Creating the database schema
Loading the entities
Creating new entities
Deleting entities
Updating entities
Conclusion

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:

Flextrine entities

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

ContactGroup.php

<?php


namespace vo;


use DoctrineCommonCollectionsArrayCollection;


/**

 * @Entity

 */


class ContactGroup {


    /** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */

    public $id;


    /** @Column(length=100, type="string") */

    public $name;


    /**

     * @OneToMany(targetEntity="Contact", mappedBy="contactGroup")

     */


    public $contacts;


    public function __construct() {

        $this->contacts = new ArrayCollection();

    }


}


?>

Contact.php

<?php

namespace vo;


use DoctrineCommonCollectionsArrayCollection;


/**

 * @Entity

 */


class Contact {


    /** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */

    public $id;


    /** @Column(length=80, type="string") */

    public $name;


    /** @Column(length=50, type="string", nullable="true") */

    public $telephoneNumber;


    /** @Column(type="date", nullable="true") */

    public $birthday;


    /**

     * @ManyToOne(targetEntity="ContactGroup", inversedBy="contacts")

     */

    public $contactGroup;


    public function __construct() {


    }


}


?>

Now that we have created our entity definitions we need to create the matching database schema.